zoukankan      html  css  js  c++  java
  • Codeforces Round #276 (Div. 2) 解题报告

    题目地址http://codeforces.com/contest/485

    A题.Factory

    模拟。判断是否出现循环,如果出现,肯定不可能。

    代码:

     1 #include<cstdio>
     2 #include<stdbool.h>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int a,m;
     9     int flag[100003]={0};
    10    
    11    scanf("%d%d",&a,&m); 
    12     while(true) {
    13     
    14         if(a%m==0){
    15             printf("Yes
    ");
    16             return 0;
    17         }
    18         if(flag[a]==1) {
    19             printf("No
    ");
    20             return 0;
    21         }
    22         flag[a]=1;
    23         a=(a+a)%m;
    24     }
    25     
    26     return 0;
    27 }

    B题:Valuable Resources

    找出横纵坐标的最大最小值,然后求最小面积。

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 
     5 const int INF=(int)1e9+3511;
     6 
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int n,x,y,maxx=-INF,maxy=-INF,minx=INF,miny=INF;
    12     
    13     scanf("%d",&n);
    14     while(n--) {
    15         scanf("%d%d",&x,&y);
    16         maxx=max(maxx,x);
    17         minx=min(minx,x);
    18         maxy=max(maxy,y);
    19         miny=min(miny,y);
    20     }
    21     
    22     int  len;
    23     len=max((maxx-minx),(maxy-miny)); 
    24     cout<<(long long )len*len<<endl;    
    25     return 0;
    26 }

    C题:Bits

    位运算。给定一个区间[L,R],问在本区间内哪个整数的二进制1的数量最多,有多个解输出最小数。

    要求二进制的1尽量多,还要求尽量小,运用位运算从低位开始把0变成1。

    从左边界开始,从低位向高位按位或(0变成1,1也还是1),直到比R大停止,输出前一个(即比R小的最后一个数)。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<iostream>
     5 
     6 #define LL  long long
     7 
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     int n;
    13     LL l,r,t,p;
    14     
    15     scanf("%d",&n);
    16     while(n--) {
    17         p=1;
    18         cin>>l>>r;
    19         for(int i=1;i<64;i++) {
    20             t=l|p;
    21             if(t>r) break;
    22             p<<=1; l=t;
    23         }
    24         cout<<l<<endl;
    25     }
    26     
    27     return 0;
    28 }

    D题:Maximum Value

    考虑到可能会出现大量相同的数,所以先排序,去掉相同的数,重新建立数列b[i]。

    对于x来说,在k*x~(k+1)*x这段范围内,余数最大的肯定是最接近(k+1)*x的数。枚举每个数的倍数,并不断更新即可。数列有序,可以通过二分查找最接近(k+1)*x的数。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 
     5 const int N=2e5+3511;
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int i,j,n,a[N],b[N],p,ans,val;
    11     
    12     scanf("%d",&n);
    13     for(int i=1;i<=n;i++) {
    14         scanf("%d",&a[i]);
    15     }
    16     
    17     sort(a+1,a+n+1);
    18     b[p=1]=a[1];
    19     for(int i=2;i<=n;i++) {
    20         if(a[i]!=a[i-1]) b[++p]=a[i];
    21     }
    22     
    23     ans=0;
    24     for(int i=1;i<p;i++) {
    25         int val=b[i],j=i;
    26         while(j<=p) {
    27             val+=b[i];
    28             j=lower_bound(b+1,b+p+1,val)-b;
    29             ans=max(ans,b[j-1]%b[i]);
    30         }
    31        
    32     }
    33     
    34     printf("%d
    ",ans);
    35     return 0;
    36 }
  • 相关阅读:
    Spring boot unable to determine jdbc url from datasouce
    Unable to create initial connections of pool. spring boot mysql
    spring boot MySQL Public Key Retrieval is not allowed
    spring boot no identifier specified for entity
    Establishing SSL connection without server's identity verification is not recommended
    eclipse unable to start within 45 seconds
    Oracle 数据库,远程访问 ora-12541:TNS:无监听程序
    macOS 下安装tomcat
    在macOS 上添加 JAVA_HOME 环境变量
    Maven2: Missing artifact but jars are in place
  • 原文地址:https://www.cnblogs.com/sxiszero/p/4103002.html
Copyright © 2011-2022 走看看