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#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#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 CF 424B. Megacity 题目意思: 给一个中心城市的坐标(0,0)和人口s,n个周围城市,告诉n个城市的人口及位置坐标,求以中心城市为圆心的最小的半径,使得人口总数超过1000000-s. 解题思路: 先求出每个城市距离中心城市的距离,然后对距离从小到大排序,然后依次扫描,如果达到要求,就退出输出最小的半径。 代码: //#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#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;} CF 424C. Magic Formulas 题目意思: 给定pi,求Q。 解题思路: 抑或运算满足交换律和结合律。 原式可以等价于先对pi全部抑或,然后对每个i(1= 预处理出dp[i]=1^2^3..^i 代码: //#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define eps 1e-6#define INF 0x3f3f3f3f#define PI acos(-1.0)#define ll __int64#define LL long long#define lson l,m,(rt