Codeforces Beta Round #9 (Div. 2 Only)

Posted fighting-sh

tags:

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

Codeforces Beta Round #9 (Div. 2 Only)

http://codeforces.com/contest/9

A

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 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 int gcd(int a,int b){
12     if(b==0) return a;
13     return gcd(b,a%b);
14 }
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18       //  freopen("1.txt","r",stdin);
19     #endif
20     int n,m;
21     cin>>n>>m;
22     n=max(n,m);
23     int fz=6-n+1;
24     int fm=6;
25     int d=gcd(fz,fm);
26    // cout<<fz<<" "<<fm<<endl;
27     cout<<fz/d<<"/"<<fm/d<<endl;
28 }
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 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 struct Point{
12     ll x,y;
13 }a[105];
14 
15 double dist[105][105];
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19         freopen("1.txt","r",stdin);
20     #endif
21     ll n,vb,vs;
22     cin>>n>>vb>>vs;
23     for(int i=1;i<=n;i++){
24         cin>>a[i].x;
25         a[i].y=0;
26     }
27     ll sx,sy;
28     cin>>sx>>sy;
29     for(int i=1;i<=n;i++){
30         dist[1][i]=sqrt(sqr(a[1].x-a[i].x)+sqr(a[1].y-a[i].y));
31     }
32     for(int i=1;i<=n;i++){
33         dist[i][103]=sqrt(sqr(a[i].x-sx)+sqr(a[i].y-sy));
34     }
35     double ans=1e18;
36     ll pos=0;
37     for(int i=1;i<=n;i++){
38         if(a[i].x!=0){
39             double t1=dist[1][i]/vb;
40             double t2=dist[i][103]/vs;
41             if(ans>=t1+t2){
42                 ans=t1+t2;
43                 pos=i;
44             }
45         }
46     }
47     cout<<pos<<endl;
48 }
View Code

 

C

dfs

技术图片
 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 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 map<ll,int>mp;
12 ll n;
13 int ans;
14 
15 void dfs(int pos){
16     if(pos>n) return;
17     if(!mp[pos]){
18         ans++;
19         mp[pos]=1;
20     }
21     else return;
22     dfs(pos*10);
23     dfs(pos*10+1);
24 }
25 
26 int main(){
27     #ifndef ONLINE_JUDGE
28        // freopen("1.txt","r",stdin);
29     #endif
30     cin>>n;
31     dfs(1);
32     cout<<ans<<endl;
33 }
View Code

 

D

参考博客:http://www.cnblogs.com/qscqesze/p/5414271.html

DP

dp[i][j]表示当前用了i个节点,高度小于等于j的方案数

dp[i][j] = sigma(dp[k][j-1]*dp[i-k-1][j-1])

 

技术图片
 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 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 long long dp[45][45];
13 
14 int main(){
15     #ifndef ONLINE_JUDGE
16        // freopen("1.txt","r",stdin);
17     #endif
18     int n,h;
19     cin>>n>>h;
20     for(int i=1;i<=n;i++){
21         dp[0][i-1]=1;
22         for(int j=1;j<=n;j++){
23             for(int k=0;k<j;k++){
24                 dp[j][i]+=dp[k][i-1]*dp[j-k-1][i-1];
25             }
26         }
27     }
28     cout<<dp[n][n]-dp[n][h-1]<<endl;
29 }
View Code

 

E

题意:给出n个点,m条边,问是否能通过加一些边,使得n个点构成有且仅有n条边的单个环

直接构造就好

技术图片
 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 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 int fa[55];
12 int d[55];
13 vector<pair<int,int> > ve,ans;
14 int Find(int x){
15     int r=x,y;
16     while(x!=fa[x]){
17         x=fa[x];
18     }
19     while(r!=x){
20         y=fa[r];
21         fa[r]=x;
22         r=y;
23     }
24     return x;
25 }
26 void join(int x,int y)
27 {
28     int xx=Find(x);
29     int yy=Find(y);
30     if(xx!=yy) fa[xx]=yy;
31 }
32 int main(){
33     int n,m;
34     cin>>n>>m;
35     int v,u;
36     for(int i=1;i<=n;i++) fa[i]=i;
37     for(int i=1;i<=m;i++){
38         cin>>u>>v;
39         ve.push_back(make_pair(u,v));
40         join(u,v);
41         d[v]++,d[u]++;
42         if(d[u]>2||d[v]>2){
43             cout<<"NO"<<endl;
44             return 0;
45         }
46     }
47     for(int i=1;i<=n;i++){
48         for(int j=1;j<i;j++){
49             if(d[j]<=1&&d[i]<=1&&Find(i)!=Find(j))
50             {
51                 ans.push_back(make_pair(j,i));
52                 join(i,j);
53                 d[i]++,d[j]++;
54             }
55         }
56     }
57     for(int i=1;i<=n;i++){
58         if(d[i]!=2){
59             for(int j=1;j<i;j++){
60                 if(d[j]==1){
61                     ans.push_back(make_pair(j,i));
62                     join(i,j);
63                     d[i]++,d[j]++;
64                 }
65             }
66         }
67     }
68     for(int i=1;i<=n;i++)
69         if(d[i]==0)ans.push_back(make_pair(i,i));
70     int p = Find(1);
71     for(int i=1;i<=n;i++)
72         if(Find(i)!=p){
73             cout<<"NO"<<endl;
74             return 0;
75         }
76     cout<<"YES"<<endl;
77     cout<<ans.size()<<endl;
78     for(int i=0;i<ans.size();i++)
79         cout<<ans[i].first<<" "<<ans[i].second<<endl;
80 }
View Code

 

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

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

Codeforces Beta Round#2

Codeforces Beta Round #7

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

Codeforces Beta Round #5

Codeforces Beta Round #3