zoukankan      html  css  js  c++  java
  • Codeforces Round #257 (Div. 2)

    Codeforces Round #257 (Div. 2)

    https://codeforces.com/contest/450/

    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 n,m;
    24 int a[105];
    25 
    26 int main(){
    27     #ifndef ONLINE_JUDGE
    28      //   freopen("1.txt","r",stdin);
    29     #endif
    30     cin>>n>>m;
    31     for(int i=0;i<n;i++){
    32         cin>>a[i];
    33     }
    34     int pos=0;
    35     int i=0;
    36     int co=0;
    37     while(1){
    38         if(a[i]>0){
    39             pos=i;
    40             a[i]-=min(m,a[i]);
    41             co=0;
    42         }
    43         else {
    44             co++;
    45         }
    46         i=(i+1)%n;
    47         if(co==n) break;
    48     }
    49     cout<<pos+1<<endl;
    50 
    51 }
    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 ll n,m,k;
    23 struct sair{
    24     ll a[3][3];
    25     sair(){
    26         a[0][0]=0,a[0][1]=0;
    27         a[1][0]=0,a[1][1]=0;
    28     }
    29     friend sair operator*(const sair&a,const sair &b){
    30         sair ans;
    31         for(int i=0;i<2;i++){
    32             for(int j=0;j<2;j++){
    33                 for(int k=0;k<2;k++){
    34                     ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j]%mod+mod)%mod;
    35                 }
    36             }
    37         }
    38         return ans;
    39     }
    40 };
    41 
    42 sair pow_mul(sair a){
    43     k-=2;
    44     sair base;
    45     base.a[0][0]=1,base.a[0][1]=0;
    46     base.a[1][0]=0,base.a[1][1]=1;
    47     while(k){
    48         if(k&1)
    49             base=base*a;
    50         k>>=1;
    51         a=a*a;
    52     }
    53     return base;
    54 }
    55 
    56 int main(){
    57     #ifndef ONLINE_JUDGE
    58      //   freopen("1.txt","r",stdin);
    59     #endif
    60     cin>>n>>m>>k;
    61     sair a;
    62     a.a[0][0]=(m+mod)%mod,a.a[0][1]=0;
    63     a.a[1][0]=(n+mod)%mod,a.a[1][1]=0;
    64     if(k==1) cout<<a.a[1][0]<<endl;
    65     else if(k==2) cout<<a.a[0][0]<<endl;
    66     else {
    67         sair base;
    68         base.a[0][0]=1,base.a[0][1]=-1;
    69         base.a[1][0]=1,base.a[1][1]=0;
    70         sair tmp=pow_mul(base);
    71         base=tmp*a;
    72         cout<<(base.a[0][0]+mod)%mod<<endl;
    73     }
    74 
    75 }
    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 main(){
    24     #ifndef ONLINE_JUDGE
    25      //   freopen("1.txt","r",stdin);
    26     #endif
    27     ll n,m,k;
    28     cin>>n>>m>>k;
    29     ll tmp=(n-1)+(m-1);
    30     if(n-1==0) tmp=m-1;
    31     if(m-1==0) tmp=n-1;
    32     if(n-1==0&&m-1==0) tmp=0;
    33     if(tmp<k) cout<<-1<<endl;
    34     else{
    35         ll ans=0;
    36         if(k>=n)ans=max(ans,m/(k-n+2));
    37         if(k>=m)ans=max(ans,n/(k-m+2));
    38         if(k<n)ans=max(ans,m*(n/(k+1)));
    39         if(k<m)ans=max(ans,n*(m/(k+1)));
    40         cout<<ans<<endl;
    41     }
    42 
    43 }
    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 n,m,k;
     24 vector<pli>ve[200005];
     25 ll dis[200005];
     26 bool book[200005];
     27 bool vis[200005];
     28 int ans;
     29 int co;
     30 void Dijstra(){
     31     priority_queue<pli,vector<pli>,greater<pli> >Q;
     32     dis[1]=0;
     33     int flag;
     34     Q.push({0,1});
     35     for(int i=0;i<=n;i++){
     36         if(book[i]==1){
     37             Q.push({dis[i],i});
     38         }
     39     }
     40     while(!Q.empty()){
     41         pli s=Q.top();
     42         Q.pop();
     43         int pos=s.second;
     44         if(!vis[pos]){
     45             vis[pos]=1;
     46             for(int i=0;i<ve[pos].size();i++){
     47                 flag=0;
     48                 int u=ve[pos][i].second;
     49                 ll len=ve[pos][i].first;
     50                 if(dis[u]>=dis[pos]+len){
     51                     if(dis[u]==dis[pos]+len){
     52                         flag=1;
     53                     }
     54                     dis[u]=dis[pos]+len;
     55                     if(book[u]){
     56                         ans++;
     57                         book[u]=0;
     58                     }
     59                     if(!flag) Q.push({dis[u],u});
     60                 }
     61             }
     62         }
     63     }
     64     for(int i=0;i<=n;i++){
     65         k-=book[i];
     66     }
     67     cout<<k<<endl;
     68 }
     69 
     70 int main(){
     71     #ifndef ONLINE_JUDGE
     72      //   freopen("1.txt","r",stdin);
     73     #endif
     74     cin>>n>>m>>k;
     75     int u,v;
     76     ll c;
     77     for(int i=0;i<=n;i++){
     78         dis[i]=0x3f3f3f3f3f3f3f3f;
     79         vis[i]=0;
     80         book[i]=0;
     81     }
     82     for(int i=1;i<=m;i++){
     83         cin>>u>>v>>c;
     84         ve[u].pb({c,v});
     85         ve[v].pb({c,u});
     86     }
     87     for(int i=1;i<=k;i++){
     88         cin>>u>>c;
     89         if(dis[u]>c){
     90             dis[u]=c;
     91             if(!book[u]){
     92                 book[u]=1;
     93             }
     94             else{
     95                 ans++;
     96             }
     97         }
     98         else{
     99             ans++;
    100         }
    101     }
    102     Dijstra();
    103     //cout<<ans<<endl;
    104 
    105 }
    View Code

    E

    模拟题+数论

     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 vector<int> a[maxn],ans;
    23 bool book[maxn];
    24 
    25 int main(){
    26     #ifndef ONLINE_JUDGE
    27      //   freopen("1.txt","r",stdin);
    28     #endif
    29     int n;
    30     cin>>n;
    31     if(n==1){
    32         cout<<0;
    33         return 0;
    34     }
    35     for(int i=3;i<=n;i++){
    36         if((i%2==1)&&book[i]==0 ){
    37             for(int j=i;j<=n;j+=i){
    38                 if(book[j]==0){
    39                     a[i].push_back(j);
    40                     book[j]=1;
    41                 }
    42 
    43             }
    44         }
    45     }
    46     for(int i=3;i<=(n/2);i++){
    47         if(a[i].size()>0){
    48             if(a[i].size()%2==1){
    49                 a[i].erase(a[i].begin()+1);
    50                 book[2*i]=0;
    51             }
    52             while(a[i].size()>0){
    53                 ans.push_back(a[i].back());
    54                 a[i].pop_back();
    55             }
    56         }
    57     }
    58     for(int i=2 ; i<=n ; i+=2){
    59         if(book[i]==0){
    60             a[2].push_back(i);
    61         }
    62     }
    63     for(int i=0;i<a[2].size()-1;i+=2){
    64         ans.push_back(a[2][i]);
    65         ans.push_back(a[2][i+1]);
    66     }
    67     int answer=(ans.size()>>1);
    68     cout<<answer<<endl;
    69     for(int i=ans.size()-1;i>=0;i-=2){
    70         cout<<ans[i]<<" "<<ans[i-1]<<endl;
    71     }
    72 }
    View Code
  • 相关阅读:
    数据库01
    并发编程6
    并发编程5
    并发编程4
    并发编程3
    并发编程2
    并发编程1
    kali 下文件操作
    kali driftnet
    2017.1.1
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10541826.html
Copyright © 2011-2022 走看看