训练3.19

1.H(简单模拟,注意细节)

 1 #include<bits/stdc++.h>
 2 #define int long long
 3 using namespace std;
 4 int er[30],q[1000000];
 5 bool cmd(char a,char b,char c)
 6 {
 7     if(a>='a'&&a<='z'&&c>='a'&&c<='z'&&a<c&&b=='-'||a>='0'&&a<='9'&&c>='0'&&c<='9'&&a<c&&b=='-')
 8         return true;
 9     else return false;
10 }
11 signed main()
12 {
13     int p1,p2,p3;
14     cin>>p1>>p2>>p3;
15     string s;
16     cin>>s;
17     for(int i=0;i<s.size();i++)
18     {
19             if (cmd(s[i - 1], s[i],s[i + 1])) {
20                 if (p1 == 1 && p3 == 1) {
21                     for (int j = s[i - 1] + 1; j < s[i + 1]; j++) {
22                         for (int k = 0; k < p2; k++)
23                             cout << (char) j;
24                     }
25                 } else if (p1 == 2 && p3 == 1) {
26                     for (int j = s[i - 1] + 1; j < s[i + 1]; j++) {
27                         for (int k = 0; k < p2; k++) {
28                             if (s[i - 1] >= 'a' && s[i - 1] <= 'z')cout << (char) (j - 32);
29                             else cout << (char) j;
30                         }
31                     }
32                 } else if (p1 == 3) {
33                     for (int j = s[i - 1] + 1; j < s[i + 1]; j++) {
34                         for (int k = 0; k < p2; k++)
35                             cout << '*';
36                     }
37                 } else if (p1 == 1 && p3 == 2) {
38                     for (int j = s[i + 1] - 1; j > s[i - 1]; j--) {
39                         for (int k = 0; k < p2; k++)
40                             cout << (char) j;
41                     }
42                 } else if (p1 == 2 && p3 == 2) {
43                     for (int j = s[i + 1] - 1; j > s[i - 1]; j--) {
44                         for (int k = 0; k < p2; k++) {
45                             if (s[i - 1] >= 'a' && s[i - 1] <= 'z')cout << (char) (j - 32);
46                             else cout << (char) j;
47                         }
48                     }
49                 } else cout << "-";
50             }
51         else cout<<s[i];
52     }
53     return 0;
54 }

2.I(通过数字所在的位置来判断二进制串下一个是0或1,再倒过来,但要注意longlong会爆,最后判断初始位,输出即可)

 1 #include<bits/stdc++.h>
 2 #define int unsigned long long
 3 using namespace std;
 4 int a[70];
 5 signed main()
 6 {
 7     int n,k;
 8     cin>>n>>k;
 9     vector<int >v;
10     int d;
11     if (n == 64) {
12         d = (1ull<<63)+(1ull<<63)-1ull;//用来取到2的64次方减一
13     }
14     else d = (1ull << n) - 1;
15     while(d>1)
16     {
17         if(d/2>=k>0)
18         {
19             v.push_back(0);
20             d/=2;
21         }
22         else
23         {
24             k=(d-k);
25             v.push_back(1);
26             d/=2;
27         }
28     }
29     std::reverse(v.begin(), v.end());
30     for(int i=0;i<v.size();i++)cout<<v[i];
31     cout<<endl;
32     string s;
33     if (k == 0) {
34         s = "0";
35     } else s = "1";
36     for (int i = 0; i < v.size(); ++i) {
37         if (v[i] == 0) {
38             s = '0' + s;
39         } else s = '1' + s;
40     }
41     cout << s << endl;
42     return 0;
43 }

3.J (结构体排序后,由于胜者和败者都是有序的数列,直接暴力不可行就利用归并排序,使用stl的merge函数排序即可)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define int  long long
 4 struct init{
 5     int a,b,c;
 6 };
 7 bool cmp(init x,init y){
 8     if(x.b!=y.b)return x.b>y.b;
 9     return x.a<y.a;
10 }
11 signed main(){
12     int n,r,q;
13     cin>>n>>r>>q;
14     n*=2;
15     vector<init>a(n);
16     for (int i = 0; i <n ; ++i)
17     {
18         cin>>a[i].b;
19         a[i].a=i+1;
20     }
21     for (int i = 0; i <n ; ++i)
22     {
23         cin>>a[i].c;
24     }
25     sort(a.begin(), a.end(),cmp);
26     while(r--){
27         vector<init>p,q;
28         for (int i = 0; i <n ; i+=2)
29         {
30             if(a[i].c>a[i+1].c){
31                 a[i].b++;
32                 p.push_back(a[i]);
33                 q.push_back(a[i+1]);
34             }
35             else
36             {
37                 a[i+1].b++;
38                 p.push_back(a[i+1]);
39                 q.push_back(a[i]);
40             }
41         }
42         merge(p.begin(),p.end(),q.begin(),q.end(),a.begin(),cmp);
43     }
44     cout<<a[q-1].a;
45 }

 

posted @ 2024-03-22 17:52  伊芙加登  阅读(10)  评论(0编辑  收藏  举报