Codeforces Beta Round #49 (Div. 2)

Posted fighting-sh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Beta Round #49 (Div. 2)相关的知识,希望对你有一定的参考价值。

Codeforces Beta Round #49 (Div. 2)

http://codeforces.com/contest/53

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 1000005
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 string s[105];
14 
15 int main(){
16     #ifndef ONLINE_JUDGE
17         freopen("input.txt","r",stdin);
18     #endif
19     std::ios::sync_with_stdio(false);
20     string str;
21     cin>>str;
22     int n;
23     cin>>n;
24     for(int i=1;i<=n;i++){
25         cin>>s[i];
26     }
27     string ans=str;
28     int flag=0;
29     for(int i=1;i<=n;i++){
30         if(s[i].find(str)==0){
31             if(!flag) ans=s[i],flag=1;
32             else ans=min(ans,s[i]);
33         }
34     }
35     cout<<ans<<endl;
36 }
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 1000005
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 #define eps 1e-8
11 typedef long long ll;
12 typedef unsigned long long ull;
13 
14 
15 ///w/h>=0.8&&w/h<=1.25
16 
17 ll num[35];
18 ll h,w;
19 
20 int sgn(double x){
21     if(x<0) return -1;
22     if(x<eps) return 0;
23     return 1;
24 }
25 vector<double>tmp;
26 
27 bool Check1(ll mid,ll h){
28     double zhi=(mid*1.0)/(h*1.0);
29     if(sgn(zhi-0.8)>=0&&sgn(1.25-zhi)>=0) return true;
30     return false;
31 }
32 
33 bool Check2(ll h,ll mid){
34     double zhi=(mid*1.0)/(h*1.0);
35     if(sgn(zhi-0.8)>=0&&sgn(1.25-zhi)>=0) return true;
36     return false;
37 }
38 
39 int main(){
40     #ifndef ONLINE_JUDGE
41      //   freopen("input.txt","r",stdin);
42     #endif
43     std::ios::sync_with_stdio(false);
44     cin>>h>>w;
45     num[0]=1;
46     ll l,r,mid;
47     ll ans=0;
48     ll ansh,answ;
49     for(int i=1;i<=30;i++) num[i]=num[i-1]*2;
50     for(int i=0;i<=30;i++){
51         if(h>=num[i]){
52             l=ll(ceil(num[i]*0.8));
53 
54             if(ll(num[i]*1.25)<=w) r=num[i]*1.25;
55             else r=w;
56          //   if(h==5&&w==5) cout<<l<<" "<<r<<endl;
57             if(l>r) continue;
58             while(l<=r){
59                 mid=l+r>>1;
60                 if(Check1(mid,num[i])) l=mid+1;
61                 else r=mid-1;
62             }
63             if(ans<=r*num[i]){
64                 ans=r*num[i];
65                 ansh=num[i],answ=r;
66             }
67         }
68     }
69     for(int i=0;i<=30;i++){
70         if(w>=num[i]){
71            /* l=ll(ceil(num[i]/0.8));
72             if(ll(num[i]/1.25)<=w) r=num[i]*1.25;
73             else r=h;*/
74             l=ceil(num[i]*1.0/1.25);
75             r=min(h,ll(num[i]*1.0/0.8));
76           //  cout<<l<<" "<<r<<endl;
77            // if(h==5&&w==5) cout<<l<<" "<<r<<endl;
78             if(l>r) continue;
79             while(l<=r){
80 
81                 mid=l+r>>1;//cout<<mid<<endl;
82                 if(Check2(num[i],mid)) l=mid+1;
83                 else r=mid-1;
84             }
85             if(ans<=r*num[i]){
86                 ans=r*num[i];
87                 answ=num[i],ansh=r;
88             }
89         }
90     }
91     if(ansh<answ){
92         if(answ<=h) swap(ansh,answ);
93     }
94     cout<<ansh<<" "<<answ<<endl;
95 }
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 1000005
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 
14 
15 int main(){
16     #ifndef ONLINE_JUDGE
17      //   freopen("input.txt","r",stdin);
18     #endif
19     std::ios::sync_with_stdio(false);
20     int n;
21     cin>>n;
22     int L=1,R=n;
23     for(int i=1;i<=n;i++){
24         if(i%2){
25             cout<<L++<<" ";
26         }
27         else{
28             cout<<R--<<" ";
29         }
30     }
31 
32 }
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 1000005
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 int a[305],b[305];
14 vector<pair<int,int> >ve;
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18      //   freopen("input.txt","r",stdin);
19     #endif
20     std::ios::sync_with_stdio(false);
21     int n;
22     cin>>n;
23     for(int i=1;i<=n;i++) cin>>a[i];
24     for(int i=1;i<=n;i++) cin>>b[i];
25     int j;
26     for(int i=1;i<=n;i++){
27         if(a[i]!=b[i]){
28             for(j=i+1;j<=n;j++){
29                 if(a[i]==b[j]){
30                     break;
31                 }
32             }
33             for(;j>i;j--){
34                 ve.pb(make_pair(j-1,j));
35                 swap(b[j],b[j-1]);
36             }
37         }
38     }
39     cout<<ve.size()<<endl;
40     for(int i=0;i<ve.size();i++){
41         cout<<ve[i].first<<" "<<ve[i].second<<endl;
42     }
43 }
View Code

 

E

状压DP

这题思路很奇妙,有些细节还没理解清楚

参考博客:https://www.luogu.org/problemnew/solution/CF53E

技术图片
 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 1000005
 9 #define rep(k,i,j) for(int k=i;k<j;k++)
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 int n,m,k;
14 int g[25][25];
15 int dp[1055][1055];
16 int ans;
17 
18 int main(){
19     #ifndef ONLINE_JUDGE
20      //   freopen("input.txt","r",stdin);
21     #endif
22     std::ios::sync_with_stdio(false);
23     cin>>n>>m>>k;
24     int u,v,x;
25     rep(i,0,m){
26         cin>>u>>v;
27         u--,v--;
28         x=(1<<u)|(1<<v);
29         g[u][v]=g[v][u]=1;
30         dp[x][x]=1;
31     }
32     rep(i,0,1<<n){
33         rep(j,0,1<<n){
34             if(i&j==j&&dp[i][j]){
35                 rep(k,0,n){
36                     rep(w,0,n){
37                         if (g[k][w]&&(i&(1<<k))&&(~i&(1<<w))&&(!(((j&(~(1<<k)))|(1<<w))>>(w+1)))){
38                             dp[i|(1<<w)][(j&(~(1<<k)))|((1<<w))]+=dp[i][j];
39                         }
40                     }
41                 }
42             }
43         }
44     }
45     int nn=(1<<n)-1;
46     rep(i,0,1<<n){
47         if(__builtin_popcount(i)==k){
48             ans+=dp[nn][i];
49         }
50     }
51     cout<<ans<<endl;
52 }
View Code

 

 

以上是关于Codeforces Beta Round #49 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Beta Round#2

Codeforces Beta Round #7

Codeforces Beta Round #6 (Div. 2)未完结

Codeforces Beta Round #5

Codeforces Beta Round #3

Codeforces Beta Round #29 (Div. 2, Codeforces format)