CF 351A - Jeff and Rounding DP】的更多相关文章

http://codeforces.com/problemset/problem/351/C 题意:有2*n个浮点数a1,a2,a3...a2*n,把他们分成n队,对于每对<A,B>,对A做floor() 操作,对B 做ceil()操作.生成b1...b2*n, 求|(b1+b2+...+b2*n)-(a1+a2+a3...+a2*n)|的最小值. 对于每个数ai,对他们做floor()的cost是up()=ai-floor(ai) ,做ceil()的cost是down()=ceil(ai)-…
http://codeforces.com/contest/352/problem/C 题意:给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 对每一个浮点数都取其下限,得到的差值就是所有浮点数小数部分的和:然后则需要从2*n个数里面选出n个数取其上限,即下限加1,而如果这个数是个整数,那么不需要加1:因此统计加1个数的上限和下限即可:然后选择min abs(小数部分的和-加1的个数): #include <cstdio> #include <…
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的数都下取整,累积更改的sum 那么选1个小数上取整,就会使sum-1 整数上下取整不会产生影响 所以有1个整数就可以使上取整的小数少1个 所以ans=min(abs(i-sum)) i∈[n-整数个数,n] #include<cmath> #include<cstdio> #inclu…
C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to sli…
C. Jeff and Rounding time limit per test:  1 second memory limit per test: 256 megabytes input: standard input output: standard output Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided t…
CF 983B XOR-pyramid(区间dp,异或) 若有一个长度为m的数组b,定义函数f为: \(f(b) = \begin{cases} b[1] & \quad \text{if } m = 1, \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise} \end{cases}\) 现在给出长度为n(n<=5000)的数组a,询问q(q<=1000…
题目链接 以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,.. #include <cstdio> #include <iostream> #include <cmath> using namespace std; #define LL __int64 LL dp[][][]; LL c[][]; int main() { int i,j,n,k,u,h; ; i <= ; i ++) { c[i][] = ; } ; i &l…
这题确实很棒..又是无想法..其实是AC自动机+DP的感觉,但是只有一个串,用kmp就行了. dp[i][j][k],k代表前缀为virus[k]的状态,len表示其他所有状态串,处理出Ac[len][26]数组来,DP就可以了.状态转移那里一直没想清楚,wa了很多次,记录路径倒是不复杂,瞎搞搞就行. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include&…
题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define LL __int64 #define MOD 2520 LL dp[][][]; ]; ]; LL gcd(…
给一个给定括号序列,给该括号上色,上色有三个要求 1.只有三种上色方案,不上色,上红色,上蓝色 2.每对括号必须只能给其中的一个上色 3.相邻的两个不能上同色,可以都不上色 求0-len-1这一区间内有多少种上色方案,很明显的区间DP dp[l][r][i][j]表示l-r区间两端颜色分别是i,j的方案数 0代表不上色,1代表上红色,2代表上蓝色 对于l-r区间,有3种情况 1.if(l+1==r) 说明就只有一对,那么dp[l][r][0][1]=1;         dp[l][r][1][…