sq

【牛客】路径计数机

痞子三分冷 提交于 2019-12-03 17:02:23
题目描述 有一棵n个点的树和两个整数p, q,求满足以下条件的四元组(a, b, c, d)的个数: 1.$1\leq a,b,c,d \leq n$ 2.点a到点b的经过的边数为p。 3.点c到点d的经过的边数为q。 4.不存在一个点,它既在点a到点b的路径上,又在点c到点d的路径上。 输入描述: 第一行三个整数n,p,q。 接下来n - 1行,每行两个整数u, v,表示树上存在一个连接点u和点v的边。 输出描述: 输出一个整数,表示答案。 示例1 输入 5 2 1 1 2 2 3 3 4 2 5 输出 4 说明 合法的四元组一共有: (1, 5, 3, 4), (1, 5, 4, 3), (5, 1, 3 ,4), (5, 1, 4, 3)。 示例2 输入 4 1 1 1 2 2 3 3 4 输出 8 备注: 对于前20%的数据,n,p,q≤50。 对于前40%的数据,n,p,q≤200。 对于另外10%的数据,p = 2, q = 2。 对于另外10%的数据,树是一条链。 对于另外10%的数据,树随机生成。 对于所有数据1≤n,p,q≤3000,1≤u,v≤n,保证给出的是一棵合法的树。 分析 我已经弱到连$n^2$枚举路径都不会了 再一次求助Master_Yi 这个题只要理顺了就挺好想的了(说得好像我想得出来似的。 由于不相交的情况不好求,所直接看相交的情况。 找规律

Yii::app()->db->createCommand($sql1)->queryAll() is not returning whole table [closed]

匿名 (未验证) 提交于 2019-12-03 10:09:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $rows = Yii::app()->db->createCommand()->select('*')->from('states')->queryAll(); above code returns only single first row, while according to documentation it should return all rows. 回答1: queryAll() returns an array and u need to iterate in order to get all the records foreach($rows as $row){ //do something } 文章来源: Yii::app()->db->createCommand($sql1)->queryAll() is not returning whole table [closed]

11 .3 数位dp

帅比萌擦擦* 提交于 2019-12-03 10:05:57
数位dp是以数位上的关系为转移关系而进行的一种计数dp,题目基本类型是给定区间[l ,r] ,求l到r之间满足要求的数字的个数 . dp状态的转移方式通常是用 递归+记忆化搜索 ,转移顺序一般是由高数位转移到底数位 ,其中就是记忆化搜索保证了数位dp的高效率 例如千位2到百位转移要枚举0,1,2,3 ...(2000,2100,2200,2300...) ,而千位3也是同样的(3000,3100,3200,3300...),其进行的都是对三位数000~999的统计,所以低位统计过程只用进行一次就可将结果应用于所有高位状态上,减少了重复过程的进行. 结果的输出形式是 0~r 之间的dp 与 0~l之间的dp 进行相减 来求 l到r 之间的 dp. printf("%lld\n",solve(r)-solve(l-1)); 值得注意的点是边界 l和r 不能进行记忆化搜索 ,比如 dp[2][sta] 记录的是 000~999(三位数) 中满足条件的数字的个数 ,而对于l = 2250 ,其在2000之后的三位数只有 100~250 ,所以这时候如果直接记忆化返回 dp[2][sta] 就会出现多记. 有的题目对前导零有要求,有的没有,做的时候随机应变。 例题: HDU 2089 不要62 题解:转移状态很清晰明了的题目,主要通过此题了解 递归+记忆化的转移方式

Using multiple databases with single sqlalchemy model

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to use multiple database engines with a single sqlalchemy database model. Following situation: I have a photo album software (python) and the different albums are stored in different folders. In each folder is a separate sqlite database with additional information about the photos. I don't want to use a single global database because with this way I can simply move, delete and copy albums on a folder base. Opening a single album is fairly straightforward: Creating a db session: maker = sessionmaker ( autoflush = True ,

Subtracting n Days from a date using SQL

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am quite a beginner when it comes to Oracle. I am having trouble figuring out how to do something similar to this : SELECT ID, NAME, TO_CHAR(DATEBIRTH, 'DD/MM/YYYY HH24:MI:SS') FROM PEOPLE WHERE DATEBIRTH >= ANOTHERDATE - NDAY To put it short, I want to select everyone who were born N days before a specific date and time but I am not quite sure that this is the way to do it nor that it would give me the results I expect. PS: I am developping under oracle8i. 回答1: Your query looks correct to me. That's how you subtract days from dates in

Convert Column from Date to Datetime Sql Server

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a column named Lastmodified , with a data type of Date , but it should have been DateTime . Is there any way of converting the column? When I use the 'Design' feature of SQL Server Management Studio I get the following error: Saving changes is not permitted. The changes you have made require the following table to be dropped and re-created. Not really interested in dropping the table, I just want to know if it is possible to convert a column from Date to Datetime or do I have to delete the column and create a new one with

How to write a select count group by SQL query in LINQ?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this query which works but when I try to write the equivalent in LINQ I get the incorrect SQL produced. My query is: SELECT COUNT(*) FROM tableName GROUP BY ColumnId I've tried writing it as: tableName.GroupBy(x => x.ColumnId).Count() But looking in LINQPad it is producing the SQL: SELECT COUNT(*) AS [value] FROM ( SELECT NULL AS [EMPTY] FROM [tableName] AS [t0] GROUP BY [t0].[ColumnId] ) AS [t1] What am I doing wrong? Thanks! 回答1: Your LINQ query is counting the number of groups but your SQL query is producing the counts by group.

基于TreeSoft实现mysql、oracle、sql server的数据同步

笑着哭i 提交于 2019-12-03 07:53:53
一、为了解决数据同步汇聚,数据分发,数据转换,数据维护需求,TreeSoft推出了数据同步,数据处理等丰富功能 。 TreeSoft作为中间传输载体负责连接各种数据源,为各种异构数据库之间架起沟通的桥梁,可实现一对多,多对多, 多对一等 复杂场景的数据同步。 支持多字段合并,字段截取,字段脱敏,数据转换,自定义函数等个性化操作。 TreeSoft已被广泛应用,每日处理大量大数据的数据维护、数据同步、数据汇聚、数据转换业务。 支持MySQL, MariaDB, Oracle, PostgreSQL, SQL Server, DB2, MongoDB, Hive, SAP HANA, Sybase, Caché, Informix, 达梦DM, 金仓Kinbase, 神通, 南大GBase等数据库。 二、兼具数据同步与数据维护管理功能,具备适应性广,灵活性强等特点。 1、支持主流RDBMS、NOSQL数据库间同步交换数据。 2、支持单节点或集群布署,可应对庞杂的业务环境。 3、支持百万级以上数据量同步。 4、企业级定时任务框架,稳定高效。 5、支持多数据源向多目标数据汇聚或数据分发。 6、支持定时数据清洗转换等后处理。 7、支持window, Linux,mac等操作系统。 8、基于JAVA开发,WEB网页管理,快速布署,到处使用。 9、基于网页灵活配置及管理,详细记录同步日志。 10

Matlab/CUDA: ocean wave simulation

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've studied "Simulating Ocean Water" article by Jerry Tessendorf and tried to program the Statistical Wave Model but I didn't get correct result and I don't understand why. In my program I tried only to create a wave height field at time t = 0 without any further changes in time. After execution of my program I got not what I was expecting: Here's my source code: clear all; close all; clc; rng(11); % setting seed for random numbers meshSize = 64; % field size windDir = [1, 0]; % ||windDir|| = 1 patchSize = 64; A = 1e+4; g = 9.81; %

How to define an unsigned integer in SQLAlchemy

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am migrating a portal to Flask with Flask-SQLAlchemy (MySQL). Below is the code I used to create my DB for my existing portal: Users = """CREATE TABLE Users( id INT UNSIGNED AUTO_INCREMENT NOT NULL, UserName VARCHAR(40) NOT NULL, FirstName VARCHAR(40) NOT NULL, LastName VARCHAR(40) NOT NULL, EmailAddress VARCHAR(255) NOT NULL, Password VARCHAR(40) NOT NULL, PRIMARY KEY (id) ) """ Here is how I am trying to use it in SQLAlchemy: class Users(db.Model): id = db.Column(db.Integer, primary_key=True) UserName = db.Column(db.String(40)) FirstName