当前位置:Gxlcms > html代码 > CodeforcesRound#242(Div.2)<A-C>_html/css_WEB-ITnose

CodeforcesRound#242(Div.2)<A-C>_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:2人阅读

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<<1)#define rson m+1,r,(rt<<1)|1#define M 1000000007//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;char save[220];int n;int main(){   //freopen("in.txt","r",stdin);   //freopen("out.txt","w",stdout);   while(~scanf("%d",&n))   {       int ans=0;       scanf("%s",save+1);       for(int i=1;i<=n;i++)            if(save[i]=='X')                ans++;       printf("%d\n",abs(n/2-ans));       if(ans=(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<=n;i++)           {               if(cnt==(ans-n/2))               {                   printf("%c",save[i]);                   continue;               }               if(save[i]=='X')               {                   cnt++;                   printf("x");               }               else                    printf("x");           }       }       putchar('\n');   }   return 0;}

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<<1)#define rson m+1,r,(rt<<1)|1#define M 1000000007//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define Maxn 1100struct Point{    double x,y;    double dis;    int v;}pp[Maxn];int n,s;int dp[Maxn];bool cmp(struct Point a,struct Point b){    return a.dis=1000000)       {           printf("0\n");           continue;       }       int lef=1000000-s;       int i=1;       while(lef>0&&i<=n)       {           ans=pp[i].dis;           lef-=pp[i].v;           i++;       }       if(lef>0)       {           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<<1)#define rson m+1,r,(rt<<1)|1#define M 1000000007//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define Maxn 1100000int dp[Maxn];int n;void init(){    dp[0]=0;    for(int i=1;i<=1000000;i++)        dp[i]=dp[i-1]^i;}int main(){   //freopen("in.txt","r",stdin);   //freopen("out.txt","w",stdout);   init();   while(~scanf("%d",&n))   {       int ans=0;       for(int i=1;i<=n;i++)       {           int p;           scanf("%d",&p);           ans=ans^p;           if((n/i)&1) //ÆæÊý           {               ans=ans^dp[i-1];           }           ans=ans^dp[n%i];       }       printf("%d\n",ans);   }   return 0;}

人气教程排行