CF424 A. Squats
题目意思:
有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列。
解题思路:
统计X的个数ans,和n/2比较,少了的话,需要把n/2-ans个x变成X,多了的话需要把ans-n/2个X变成x.(从前往后扫一遍就行了)。
代码:
//#include<cspreadsheet.h>#include<iostream>#include<cmath>#include<cstdio>#include<sstream>#include<cstdlib>#include<string>#include<string.h>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<ctime>#include<bitset>#include<cmath>#define eps 1e-6#define INF 0x3f3f3f3f#define PI acos(-1.0)#define ll __int64#define LL long long#define lson l,m,(rt=(n/2-ans)) { printf("%c",save[i]); continue; } if(save[i]=='x') { cnt++; printf("X"); } else printf("X"); } } else { int cnt=0; for(int i=1;i <br> CF 424B. Megacity <p></p> <p>题目意思:</p> <p>给一个中心城市的坐标(0,0)和人口s,n个周围城市,告诉n个城市的人口及位置坐标,求以中心城市为圆心的最小的半径,使得人口总数超过1000000-s.</p> <p>解题思路:</p> <p>先求出每个城市距离中心城市的距离,然后对距离从小到大排序,然后依次扫描,如果达到要求,就退出输出最小的半径。</p> <p>代码:</p> <p></p> <pre name="code" class="sycode">//#include<cspreadsheet.h>#include<iostream>#include<cmath>#include<cstdio>#include<sstream>#include<cstdlib>#include<string>#include<string.h>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<ctime>#include<bitset>#include<cmath>#define eps 1e-6#define INF 0x3f3f3f3f#define PI acos(-1.0)#define ll __int64#define LL long long#define lson l,m,(rt=1000000) { printf("0\n"); continue; } int lef=1000000-s; int i=1; while(lef>0&&i0) { printf("-1\n"); continue; } printf("%lf\n",ans); } return 0;}</cmath></bitset></ctime></queue></list></stack></set></map></vector></algorithm></cstring></string.h></string></cstdlib></sstream></cstdio></cmath></iostream></cspreadsheet.h>
CF 424C. Magic Formulas
题目意思:
给定pi,求Q。
解题思路:
抑或运算满足交换律和结合律。
原式可以等价于先对pi全部抑或,然后对每个i(1=
预处理出dp[i]=1^2^3..^i
代码:
//#include<cspreadsheet.h>#include<iostream>#include<cmath>#include<cstdio>#include<sstream>#include<cstdlib>#include<string>#include<string.h>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<ctime>#include<bitset>#include<cmath>#define eps 1e-6#define INF 0x3f3f3f3f#define PI acos(-1.0)#define ll __int64#define LL long long#define lson l,m,(rt <br> <br> <p></p> <p><br> </p> <p><br> </p> </cmath></bitset></ctime></queue></list></stack></set></map></vector></algorithm></cstring></string.h></string></cstdlib></sstream></cstdio></cmath></iostream></cspreadsheet.h>