随笔分类 - Codeforces
my codeforces
摘要:http://www.codeforces.com/problemset/problem/55/DView Code //dp[i][j][k] 表示长度为i的,对2520取模为j的,最小公倍数为k的数的个数,1~9最小公倍数只有48个,预处理出来。const int MM = 11111;typedef __int64 int64;#define mod 2520#define debug puts("wrong")int64 N,L,R;int num[MM],cnt;int64 dp[19][2520][50];int id[MM], g;void get_init(
阅读全文
摘要:http://codeforces.com/problemset/problem/50/C记录出轮廓线,计算出走的长度, ans+4View Code void get_data() { int64 i,j,k; for(i=0;i<N;i++) scanf("%I64d%I64d",&g[i].x,&g[i].y);}void solve() { int64 i,j,k,x,y,ans=0,cnt; cnt=graham(g,N,res); for(i=1;i<cnt;i++) { // printf("%d %d\n",r
阅读全文
摘要:http://codeforces.com/problemset/problem/51/B利用stack类似与括号匹配,每个<table>ROWS</table> 划分一个模块,一个<td>TABLE</td>记录多少个CELL, stack中存的是模块的序号。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define maxint 0x3f3f3f3ftypedef __int64 int64;#define debug put
阅读全文
摘要:http://codeforces.com/problemset/problem/51/C两次二分+贪心, 被卡精度卡了好久,发现整数点的话,结果不是整数就是 xxx.5的直接整数解决,就不会有精度问题啦。以后注意利用题目条件, double代码留作纪念。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define debug puts("wrong")#define clr(a) memset(a,0,sizeof(a))int N,M,mm;int x[M
阅读全文
摘要:http://codeforces.com/problemset/problem/38/EDP状态很容易想到,以后超long long 最大值的设定最好计算出一个边界, int_max的边界赋值 错误,导致WA那么多次。View Code #include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <set>#include <map>#include <queue>#include <fstream>#
阅读全文
摘要:http://codeforces.com/problemset/problem/39/A贪心 按照常数大小从小到大排序, 结果一个一个计算上来, 不影响结果正确性。View Code #include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <set>#include <map>#include <queue>#include <fstream>#include <string>#incl
阅读全文
摘要:http://www.codeforces.com/problemset/problem/266/D资料:最小直径生成树
阅读全文
摘要:C. Almost Arithmetical Progression精神恍惚的把题目看错了,说实话就算真的是精神恍惚这样也太水了吧。排序+胡搞,标签上写着DP,实在想不出来状态怎么转移。胡搞都搞不出来,就不想DP解法了。code:这里D. Mr. Bender and Square类似于病毒向外蔓延,随着时间的增加覆盖的面积会一直增加,可以二分。主要是计算给定一个时间计算其覆盖的面积。类似于容斥的思想。画个清楚点的图模拟一下就很容易发现规律。ans=2*m*m+2*m+1-(四个方向超出边界的)+(相邻两个边界重合的部分)code:这里
阅读全文
摘要:C. Anagram贪心,先算出最小需要修改多少的字符。O(N)从前往后扫一遍,如果这个数需要变的比他小的字母,就直接改变,否则,把这个修改延迟,设置一个pre[]记录这个字符之前进过多少个字母,到不得不修改时,在修改,类似于延迟标记。没有一眼看出水的本质。View Code freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);有时候需要文件操作,略恶心,记录一下。code:点这里
阅读全文
摘要:C. Points on Line很水的二分查找,但是由于查找边界设置错了,一直错到最后。复杂度O(N log N).对于每个位置x-->pos=find(x),find()函数中ll=x,rr=N-1。(我ll定义成从第0个开始,这样会导致重复查找)最近的状态都是渣一样的。
阅读全文
摘要:D. Building Bridge两点之间直线最短,相似三角形求出在A上的点,二分查找最接近这点的点,B河岸上扫一遍求出最小距离时分别对应A,B河岸上的点,复杂度O(mlogN)
阅读全文
摘要:B. Restoring IPv6状态不好,看来好久才看出题意,字符处理始终是我的弱项,有空联系下。记录一下。View Code 1 #include <iostream> 2 #include <cassert> 3 #include <cstdio> 4 #include <cstring> 5 #include <vector> 6 #include <algorithm> 7 using namespace std; 8 9 const int MM = 110010;10 #define fuck puts(&q
阅读全文
摘要:C. Movie Critics先对原输入的数组对连续相同的元素去重。O(N)扫一遍记录删除每一位元素所改变的波动。有两种情况:A.两端元素由x y,.....和.....y x两种情况,删掉x波动减一。B.x不在两端有...y x z...,B.1删掉x当y=z时,波动减2 B.2当y!=z时,虽然去掉x波动减2,但y z组合波动又加1,所以总的贡献度+1。复杂度O(N).
阅读全文
摘要:昨晚做题的感觉不是很好,第一次做codeforces 被B卡死,E加两个 in和out 标记,+和-都分别更新in,out,结果in+out,以后要加强出题速度。传送门:http://codeforces.com/contest/245我还是太弱了,一再强调想法是关键,不能随便看题解和别人代码。come on!!
阅读全文