• Codeforces Round #450 (Div. 2)


    Codeforces Round #450 (Div. 2)

    http://codeforces.com/contest/900

    A

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define eb emplace_back
     8 #define maxn 100005
     9 #define eps 1e-8
    10 #define pi acos(-1.0)
    11 #define rep(k,i,j) for(int k=i;k<j;k++)
    12 typedef long long ll;
    13 typedef pair<int,int> pii;
    14 typedef pair<long long,int>pli;
    15 typedef pair<int,char> pic;
    16 typedef pair<pair<int,string>,pii> ppp;
    17 typedef unsigned long long ull;
    18 const long long MOD=1e9+7;
    19 /*#ifndef ONLINE_JUDGE
    20         freopen("1.txt","r",stdin);
    21 #endif */
    22 
    23 int a[2];
    24 int main(){
    25     #ifndef ONLINE_JUDGE
    26      //   freopen("1.txt","r",stdin);
    27     #endif
    28     std::ios::sync_with_stdio(false);   
    29     int n;
    30     cin>>n;
    31     int u,v;
    32     for(int i=0;i<n;i++){
    33         cin>>u>>v;
    34         if(u>0) a[0]++;
    35         else a[1]++;
    36     }
    37     if(a[0]<=1||a[1]<=1) cout<<"YES"<<endl;
    38     else cout<<"NO"<<endl;
    39 }
    View Code

    B

    模拟除法

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define eb emplace_back
     8 #define maxn 100005
     9 #define eps 1e-8
    10 #define pi acos(-1.0)
    11 #define rep(k,i,j) for(int k=i;k<j;k++)
    12 typedef long long ll;
    13 typedef pair<int,int> pii;
    14 typedef pair<long long,int>pli;
    15 typedef pair<int,char> pic;
    16 typedef pair<pair<int,string>,pii> ppp;
    17 typedef unsigned long long ull;
    18 const long long MOD=1e9+7;
    19 /*#ifndef ONLINE_JUDGE
    20         freopen("1.txt","r",stdin);
    21 #endif */
    22 
    23 int a[2];
    24 ll fac[15];
    25 int main(){
    26     #ifndef ONLINE_JUDGE
    27      //   freopen("1.txt","r",stdin);
    28     #endif
    29     int a,b,c;
    30     cin>>a>>b>>c;
    31     int co=1;
    32     while(1){
    33         a*=10;
    34         int k=a/b;
    35         a%=b;
    36         if(k==c){
    37             cout<<co<<endl;
    38             return 0;
    39         }
    40         co++;
    41         if(co>=100000) break;
    42     }
    43     cout<<-1<<endl;
    44 
    45 }
    View Code

    C

    找规律

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define eb emplace_back
     8 #define maxn 100005
     9 #define eps 1e-8
    10 #define pi acos(-1.0)
    11 #define rep(k,i,j) for(int k=i;k<j;k++)
    12 typedef long long ll;
    13 typedef pair<int,int> pii;
    14 typedef pair<long long,int>pli;
    15 typedef pair<int,char> pic;
    16 typedef pair<pair<int,string>,pii> ppp;
    17 typedef unsigned long long ull;
    18 const long long MOD=1e9+7;
    19 /*#ifndef ONLINE_JUDGE
    20         freopen("1.txt","r",stdin);
    21 #endif */
    22 
    23 int n;
    24 int a[maxn],cnt[maxn];
    25 
    26 int main(){
    27     #ifndef ONLINE_JUDGE
    28      //   freopen("1.txt","r",stdin);
    29     #endif
    30     cin>>n;
    31     int max1=0,max2=0;
    32     for(int i=1;i<=n;i++) cin>>a[i];
    33     for(int i=1;i<=n;i++){
    34         if(a[i]>max1){
    35             max2=max1;
    36             max1=a[i];
    37             cnt[a[i]]--;
    38         }
    39         else if(a[i]>max2){
    40             cnt[max1]++;
    41             max2=a[i];
    42         }
    43     }
    44     int max3=-maxn,ans;
    45     for(int i=1;i<=n;i++){
    46         if(cnt[i]>max3){
    47             max3=cnt[i];
    48             ans=i;
    49         }
    50     }
    51     cout<<ans<<endl;
    52 
    53 }
    View Code

    D

    记忆化搜索+容斥

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define eb emplace_back
     8 #define maxn 100005
     9 #define eps 1e-8
    10 #define pi acos(-1.0)
    11 #define rep(k,i,j) for(int k=i;k<j;k++)
    12 typedef long long ll;
    13 typedef pair<int,int> pii;
    14 typedef pair<long long,int>pli;
    15 typedef pair<int,char> pic;
    16 typedef pair<pair<int,string>,pii> ppp;
    17 typedef unsigned long long ull;
    18 const long long MOD=1e9+7;
    19 /*#ifndef ONLINE_JUDGE
    20         freopen("1.txt","r",stdin);
    21 #endif */
    22 
    23 int x,y;
    24 map<int,int>mp;
    25 
    26 ll pow_mul(ll a,ll b){
    27     ll ans=1;
    28     while(b){
    29         if(b&1) ans=(ans*a)%MOD;
    30         b>>=1;
    31         a=(a*a)%MOD;
    32     }
    33     return ans;
    34 }
    35 
    36 ll dp(int x){
    37     if(x==1) return 1;
    38     if(mp.count(x)) return mp[x];
    39     mp[x]=pow_mul(2,x-1);
    40     for(int i=2;i*i<=x;i++){
    41         if(x%i==0){
    42             mp[x]=(mp[x]-dp(x/i)+MOD)%MOD;
    43             if(i!=x/i){
    44                 mp[x]=(mp[x]-dp(i)+MOD)%MOD;
    45             }
    46         }
    47     }
    48     return mp[x]=(mp[x]-dp(1)+MOD)%MOD;
    49 }
    50 
    51 int main(){
    52     #ifndef ONLINE_JUDGE
    53      //   freopen("1.txt","r",stdin);
    54     #endif
    55     cin>>x>>y;
    56     if(y%x){
    57         cout<<0<<endl;
    58     }
    59     else{
    60         cout<<dp(y/x)<<endl;
    61     }
    62 
    63 }
    View Code

    E

    DP

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define eb emplace_back
     8 #define maxn 100005
     9 #define eps 1e-8
    10 #define pi acos(-1.0)
    11 #define rep(k,i,j) for(int k=i;k<j;k++)
    12 typedef long long ll;
    13 typedef pair<int,int> pii;
    14 typedef pair<long long,int>pli;
    15 typedef pair<int,char> pic;
    16 typedef pair<pair<int,string>,pii> ppp;
    17 typedef unsigned long long ull;
    18 const long long MOD=1e9+7;
    19 /*#ifndef ONLINE_JUDGE
    20         freopen("1.txt","r",stdin);
    21 #endif */
    22 pii d[maxn];
    23 int f[3][maxn], n, m, b[maxn];
    24 char a[maxn];
    25 
    26 int main(){
    27     #ifndef ONLINE_JUDGE
    28      //   freopen("1.txt","r",stdin);
    29     #endif
    30      cin >> n;
    31     for (int i = 1; i <= n; i++)
    32         cin >> a[i];
    33     cin >> m;
    34     for (int i = 1; i <= n; i++)
    35     {
    36         if (a[i] == '?')
    37             b[i] = b[i-1] + 1;
    38         else b[i] = b[i-1];
    39         if (a[i] != 'a')
    40             f[1][i] = f[0][i-1]+1;
    41         if (a[i] != 'b')
    42             f[0][i] = f[1][i-1]+1;
    43         if (f[!(m&1)][i] >= m)
    44             d[i] = {d[i-m].first + 1, -(b[i]-b[i-m]-d[i-m].second)};
    45         d[i] = max(d[i-1], d[i]);
    46     }
    47     cout << - d[n].second;
    48 
    49 }
    View Code
  • 相关阅读:
    union
    大端和小端
    迭代器
    STL
    动态内存管理2
    动态内存管理
    关于 FlexBox
    CSS的居中问题
    操作符
    JavaScript介绍
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10538681.html
Copyright © 2020-2023  润新知