首页 > 代码库 > Educational Codeforces Round 24

Educational Codeforces Round 24

A题

分析:SB题,列一个式子搞定

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 using namespace std;
 6 long long n,k;
 7 int main()
 8 {
 9     cin>>n>>k;
10     long long num=n/2;
11     num/=(k+1);
12     cout<<num<<" "<<(num*k)<<" "<<(n-num*(k+1))<<endl;
13     return 0;
14 }
View Code

B题

分析:模拟,通过给定条件求出要求序列,注意一下不合法条件的判定

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 #include "cmath"
 6 #include "vector"
 7 using namespace std;
 8 const int maxn=110;
 9 int n,m;
10 int l[maxn],a[maxn];
11 int vis[maxn];
12 int main()
13 {
14     cin>>n>>m;
15     for(int i=1;i<=m;i++)
16         cin>>l[i];
17     int num;
18     int flag=0;
19     memset(a,0,sizeof(a));
20     for(int i=1;i<=m-1;i++){
21         if(l[i+1]>l[i]){
22             num=l[i+1]-l[i];
23         }else{
24             num=l[i+1]+n-l[i];
25         }
26         if(a[l[i]]){
27             if(num!=a[l[i]]){
28                 flag=1; break;
29             }
30         }
31         else a[l[i]]=num;
32     }
33     if(flag){
34         cout<<"-1"<<endl;
35         return 0;
36     }
37     /*for(int i=1;i<=n;i++)
38         cout<<a[i]<<" ";
39     cout<<endl;*/
40     memset(vis,0,sizeof(vis));
41         for(int i=1;i<=n;i++)
42             vis[a[i]]++;
43     //int flag=0;
44         for(int i=1;i<=n;i++)
45             if(vis[i]>1){
46                 flag=1; break;
47             }
48         if(flag){
49             cout<<"-1"<<endl;
50         }else{
51             vector<int>h;
52             for(int i=1;i<=n;i++)
53                 if(!vis[i])
54                     h.push_back(i);
55             int k=0;
56             for(int i=1;i<=n;i++)
57                 if(!a[i])
58                     a[i]=h[k++];
59             for(int i=1;i<=n;i++){
60                 if(i==n) cout<<a[i]<<endl;
61                 else  cout<<a[i]<<" ";
62             }
63         }
64     return 0;
65 }
View Code

D题

分析:动态统计每个数出现的次数,一旦出现该数在某个位置出现的次数比A小,则淘汰

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 using namespace std;
 6 const int maxn=1e6+10;
 7 int vis[maxn],d[maxn];
 8 int n,A;
 9 int main()
10 {
11     cin>>n>>A;
12     vis[A]=1;
13     for(int i=1;i<=n;i++){
14         int x;
15         scanf("%d",&x);
16         if(d[x]<d[A]) vis[x]=1;
17         d[x]++;
18     }
19     int pos=-1;
20     for(int i=1;i<=maxn-10;i++)
21         if(d[i]>=d[A]&&!vis[i]){
22             pos=i; break;
23         }
24     cout<<pos<<endl;
25 }
View Code

 

Educational Codeforces Round 24