Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]

Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]

https://codeforces.com/contest/1068

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 300005
 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 
24 
25 
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30     std::ios::sync_with_stdio(false);
31     ll n,m,k,l;
32     cin>>n>>m>>k>>l;
33     if(n<m||n-k<l){
34            cout<<-1<<endl;
35         return 0;
36     }
37     ll res=(k+l)/m; 
38     if(res*m<k+l) ++res; 
39     if(res*m<=n) cout<<res<<endl;
40     else cout<<-1<<endl;
41 }
View Code

 

B

数论

因为lcm(a,b)/a==b/gcd(a,b),又因为b是确定的,所以求的是gcd(a,b)的个数,也就是求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 300005
 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 
24 
25 
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30     std::ios::sync_with_stdio(false);
31     ll n;
32     cin>>n;
33     int sq=sqrt(n);
34     ll ans=1;
35     for(int i=2;i<=sq;i++){
36         ll co=1;
37         while(n%i==0){
38             n/=i;
39             co++;
40         }
41         ans*=co;
42     }
43     if(n>1) ans*=2;
44     cout<<ans<<endl;
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 300005
 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 
24 vector<int>ve[105];
25 int n,m;
26 
27 int main(){
28     #ifndef ONLINE_JUDGE
29      //   freopen("1.txt","r",stdin);
30     #endif
31     std::ios::sync_with_stdio(false);
32     cin>>n>>m;
33     for(int i=1;i<=n;i++){
34         ve[i].pb(i);
35     }
36     int x,y;
37     int co=n+1;
38     for(int i=0;i<m;i++){
39         cin>>x>>y;
40         ve[x].pb(co);
41         ve[y].pb(co);
42         co++;
43     }
44     for(int i=1;i<=n;i++){
45         cout<<ve[i].size()<<endl;
46         for(int j=0;j<ve[i].size();j++){
47             cout<<i<<" "<<ve[i][j]<<endl;
48         }
49     }
50 }
View Code

 

D

DP

参考博客:https://blog.csdn.net/white_156/article/details/83421537

 1 #include<iostream>
 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=998244353;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22 
23 int a[100005];
24 long long dp[100005][205][2];
25 
26 
27 int main(){
28     #ifndef ONLINE_JUDGE
29      //   freopen("1.txt","r",stdin);
30     #endif
31     std::ios::sync_with_stdio(false);
32     int n;
33     scanf("%d",&n);
34     for(int i=1;i<=n;i++) cin>>a[i];
35     if(a[1]!=-1){
36         dp[1][a[1]][0]=1;
37     }
38     else{
39         for(int i=1;i<=200;i++){
40             dp[1][i][0]=1;
41             dp[1][i][1]=0;
42         }
43     }
44     for(int i=2;i<=n;i++){
45         if(a[i]==-1){
46             dp[i][1][0]=0;
47             for(int j=2;j<=200;j++)
48                 dp[i][j][0]=(dp[i][j][0]+dp[i][j-1][0]+dp[i-1][j-1][0]+dp[i-1][j-1][1])%mod;
49             dp[i][200][1]=0;
50             for(int j=199;j>=1;j--){
51                 dp[i][j][1]=(dp[i][j][1]+dp[i][j+1][1]+dp[i-1][j+1][1])%mod;
52             }
53             for(int j=1;j<=200;j++)
54                 dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][1]+dp[i-1][j][0])%mod;
55         }
56         else{
57             int num=a[i];
58             for(int j=1;j<num;j++)
59                 dp[i][num][0]=(dp[i][num][0]+dp[i-1][j][0]+dp[i-1][j][1])%mod;
60             for(int j=num+1;j<=200;j++)
61                 dp[i][num][1]=(dp[i][num][1]+dp[i-1][j][1])%mod;
62             dp[i][num][1]=(dp[i][num][1]+dp[i-1][num][0]+dp[i-1][num][1])%mod;
63         }
64     }
65     long long ans=0;
66     for(int i=1;i<=200;i++)
67         ans=(ans+dp[n][i][1])%mod;
68     cout<<ans<<endl;
69 
70     
71     
72 }
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=998244353;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22 
23 set<int>se[maxn],v,t;
24 set<int>::iterator it;
25 int cnt[maxn];
26 
27 
28 int main(){
29     #ifndef ONLINE_JUDGE
30      //   freopen("1.txt","r",stdin);
31     #endif
32     std::ios::sync_with_stdio(false);
33     int n,k;
34     cin>>n>>k;
35     for(int i=1;i<n;i++)
36     {
37         int u,v;
38         cin>>u>>v;
39         se[u].insert(v);
40         se[v].insert(u);
41     }
42     for(int i=1;i<=n;i++)
43         if(se[i].size()==1)
44             v.insert(i);
45     while(n>1)
46     {
47         t.clear();
48         for(it=v.begin();it!=v.end();it++)
49         {
50             int x=*se[*it].begin();
51             cnt[x]++;
52             t.insert(x);
53             se[x].erase(*it);
54             n--;
55         }
56         for(it=t.begin();it!=t.end();it++)
57         {
58             if(cnt[*it]<3)
59             {
60                 printf("No\n");
61                 return 0;
62             }
63             cnt[*it]=0;
64         }
65         swap(v,t);
66         k--;
67     }
68     if(k==0)printf("Yes\n");
69     else printf("No\n");
70 
71     
72     
73 }
View Code

 

posted on 2019-03-18 10:08  Fighting_sh  阅读(214)  评论(0编辑  收藏  举报

导航