Codeforces Beta Round #16 (Div. 2 Only)

Codeforces Beta Round #16 (Div. 2 Only)

http://codeforces.com/contest/16

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 maxn 500005
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int n,m;
13 string str[105];
14 
15 int main(){
16     #ifndef ONLINE_JUDGE
17        // freopen("1.txt","r",stdin);
18     #endif
19     cin>>n>>m;
20     int flag=0;
21     map<int,int>mp;
22     for(int i=0;i<n;i++) cin>>str[i];
23     for(int i=1;i<n;i++){
24         if(str[i][0]==str[i-1][0]) flag=1;
25     }
26     if(!flag){
27         if(m==1){
28             cout<<"YES"<<endl;
29         }
30         else{
31             for(int k=0;k<n;k++){
32                 for(int i=1;i<m;i++){
33                     if(str[k][i]!=str[k][i-1]) flag=1;
34                 }
35             }
36             if(flag) cout<<"NO"<<endl;
37             else  cout<<"YES"<<endl;
38         }
39     }
40     else{
41         cout<<"NO"<<endl;
42     }
43 }
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 maxn 500005
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 struct sair{
13     ll num,val;
14 }a[25];
15 
16 bool cmp(sair a,sair b){
17     return a.val>b.val;
18 }
19 
20 int main(){
21     #ifndef ONLINE_JUDGE
22        // freopen("1.txt","r",stdin);
23     #endif
24     ll n,m;
25     cin>>n>>m;
26     for(int i=1;i<=m;i++){
27         cin>>a[i].num>>a[i].val;
28     }
29     sort(a+1,a+m+1,cmp);
30     ll ans=0;
31     for(int i=1;i<=m;i++){
32         if(n>=a[i].num){
33             ans+=a[i].num*a[i].val;
34             n-=a[i].num;
35         }
36         else if(n<a[i].num){
37             ans+=a[i].val*n;
38             n=0;
39         }
40         if(!n) break;
41     }
42     cout<<ans<<endl;
43 }
View Code

 

C

gcd

 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 maxn 500005
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 ll gcd(ll a,ll b){
13     if(b==0) return a;
14     return gcd(b,a%b);
15 }
16 int main(){
17     #ifndef ONLINE_JUDGE
18        // freopen("1.txt","r",stdin);
19     #endif
20     ll a,b,c,d;
21     cin>>a>>b>>c>>d;
22     ll x=gcd(c,d);
23     c/=x;
24     d/=x;
25     x=min(a/c,b/d);
26     cout<<c*x<<" "<<d*x<<endl;
27 }
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 maxn 500005
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 string str;
12 
13 int Change(char ch1,char ch2){
14     return (ch1-'0')*10+(ch2-'0');
15 }
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19         freopen("1.txt","r",stdin);
20     #endif
21    // std::ios::sync_with_stdio(false);
22     int n;
23     scanf("%d%*c",&n);
24     int pres=25,pref=61;
25     int ans=0;
26     int co=1;
27     for(int i=1;i<=n;i++){
28         getline(cin,str);
29       //  cout<<str<<" "<<i<<endl;
30         char flag=str[7];
31         int shi=Change(str[1],str[2]);
32         int fen=Change(str[4],str[5]);
33         if(flag=='p') shi+=12;
34         if(shi==12&&flag=='a') shi=0;
35         if(shi==24&&flag=='p') shi=12;
36        // cout<<pres<<" "<<pref<<" "<<shi<<" "<<fen<<endl;
37         if(shi==pres&&fen==pref) co++;
38         else {
39             co=1;
40         }
41         if(co>10) {
42             co=1;
43             ans++;
44         }
45         if(shi<pres||(shi==pres&&fen<pref)){
46             ans++;
47         }
48         pres=shi;
49         pref=fen;
50     }
51     cout<<ans<<endl;
52 }
View Code

 

E

状压DP


dp(ij)=dp(ij)p(ij)prob(ij)

 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 maxn 500005
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int n;
13 double a[25][25];
14 
15 double dp[1<<19];
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19         freopen("1.txt","r",stdin);
20     #endif
21     std::ios::sync_with_stdio(false);
22     cin>>n;
23     for(int i=0;i<n;i++){
24         for(int j=0;j<n;j++){
25             cin>>a[i][j];
26         }
27     }
28     dp[(1<<n)-1]=1;///所有鱼都存在的情况
29     for(int i=(1<<n)-1;i;i--){
30         int num=0;
31         for(int j=0;j<n;j++){
32             if(i&(1<<j)) num++;///判断存活鱼的个数
33         }
34         for(int j=0;j<n;j++){
35             if(i&(1<<j)){///j存活
36                 for(int k=j+1;k<n;k++){
37                     if(i&(1<<k)){///k存活
38                         dp[i-(1<<k)]+=dp[i]*a[j][k]*1.0/(num*(num-1)/2);  ///j吃k
39                         dp[i-(1<<j)]+=dp[i]*a[k][j]*1.0/(num*(num-1)/2); ///k吃j
40                     }
41                 }
42             }
43         }
44     }
45     for(int i=0;i<n;i++){
46         cout<<dp[1<<i]<<" ";
47     }
48     cout<<endl;
49 }
View Code

 

posted on 2019-02-07 17:34  Fighting_sh  阅读(113)  评论(0编辑  收藏  举报

导航