zoukankan      html  css  js  c++  java
  • codeforces round#613

    A题:输出n+1;

    B题:

    题意:就是给n个数,a人全拿,b人拿连续的子段和,如果b人比a人大于等于的话输出NO,反之输出YES

    思路:最大子段和,比赛的时候忘记 ll 和 字段和不是遇到负数就重置。

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<set>
     6 #include<map>
     7 #include<queue>
     8 #include<vector>
     9 #include<queue>
    10 #include<cmath>
    11 #define mem(a,b) memset(a,b,sizeof(a))
    12 using namespace std;
    13 #define ll long long
    14 #define inf 0x3f3f3f3f
    15 #define mod 998244353
    16 const int maxn=1e5+10;
    17 int t,n;
    18 int a[maxn];
    19 int main(){
    20     scanf("%d",&t);
    21     while(t--){
    22         scanf("%d",&n);
    23         int flag=1,tt=0,f=1;
    24         ll sum=0,ans=0,maxx=-1;
    25         for(int i=0;i<n;i++){
    26             scanf("%d",&a[i]);
    27             sum+=(ll)a[i];
    28         }
    29         ans=0;
    30         int l=0,r=0,l1=0,r1=0;
    31         for(int i=0;i<n;i++){
    32            if(ans<=0){ans=a[i];l=r=i;}
    33            else{
    34                 ans+=a[i];r=i;
    35            }
    36            if(maxx<ans){
    37                 maxx=ans,l1=l,r1=r;
    38            }
    39         }
    40         if(maxx<sum ||(maxx==sum && l1==0 && r1==n-1)){
    41             printf("YES
    ");
    42         }
    43         else{
    44             printf("NO
    ");
    45         }
    46     }
    47     return 0;
    48 }
    View Code

    C题:

    题意:给一个x,求lcm(a,b)=x的同时max(a,b)要求最小化

    思路:比赛的时候想了一个想法,然后试了一下就过了,没有数学验证,感觉这题比B题好做好多

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<set>
     6 #include<map>
     7 #include<queue>
     8 #include<vector>
     9 #include<queue>
    10 #include<cmath>
    11 #define mem(a,b) memset(a,b,sizeof(a))
    12 using namespace std;
    13 #define ll long long
    14 #define inf 0x3f3f3f3f
    15 #define mod 998244353
    16 const int maxn=1e5+10;
    17 ll gcd(ll a,ll b){
    18     return b==0?a:gcd(b,a%b);
    19 }
    20 ll n;
    21 int main(){
    22     scanf("%lld",&n);
    23     ll k=(ll)sqrt(n);
    24     for(ll i=k;i>=1;i--){
    25         if(n%i==0){
    26             if(gcd(i,n/i)==1){
    27                 printf("%lld %lld
    ",i,n/i);break;
    28             }
    29         }
    30     }
    31     return 0;
    32 }
    View Code

    upd

    D题:看网上代码和思路,自己的假算法一直过不去……

    这是一道异或的题,题意是给n个数字,找到一个X,和n个数异或,使得异或结果最大maxx的那个最小化,输出maxx

    思路:(其实还是不太明白为什么可以这样,抄了一位大哥的题解,自己再琢磨琢磨……)

    dfs,遍历这些数当前二进制位置是否全为1,或者全为0,如果都是1或0,当前二进制就可以抵消,不然再选择X的时候,这位的二进制是1或者0,都只能抵消一个二进制上面的数

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cstdio>
     5 #include<set>
     6 #include<map>
     7 #include<queue>
     8 #include<vector>
     9 #include<queue>
    10 #include<cmath>
    11 #define mem(a,b) memset(a,b,sizeof(a))
    12 using namespace std;
    13 #define ll long long
    14 #define inf 0x3f3f3f3f
    15 #define mod 998244353
    16 const int maxn=1e5+10;
    17 vector<int>g;
    18 int n,t;
    19 int dfs(vector<int>&c,int x){
    20     if(x<0){return 0;}
    21     if(c.size()==0){return 0;}
    22     vector<int>on,off;
    23     for(auto i:c){
    24         if((i>>x)&1){
    25             on.push_back(i);
    26         }
    27         else{
    28             off.push_back(i);
    29         }
    30     }
    31     if(on.size()==0){return dfs(off,x-1);}
    32     if(off.size()==0){return dfs(on,x-1);}
    33     return min(dfs(off,x-1),dfs(on,x-1))+(1<<x);
    34 }
    35 int main(){
    36     scanf("%d",&n);
    37     for(int i=0;i<n;i++){
    38         scanf("%d",&t);g.push_back(t);
    39     }
    40     printf("%d
    ",dfs(g,29));
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    [React] {svg, css module, sass} support in Create React App 2.0
    [NPM] npm check to update the dependencies
    [RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS
    [RxJS] Implement RxJS `concatMap` by Waiting for Inner Subscriptions to Complete
    [React] PureComponent in React
    [RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through
    [RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through
    [RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce
    [RxJS] Implement the `map` Operator from Scratch in RxJS
    [RxJS] Create a Reusable Operator from Scratch in RxJS
  • 原文地址:https://www.cnblogs.com/luoyugongxi/p/12181495.html
Copyright © 2011-2022 走看看