当前位置:网站首页>#797div3 A---C

#797div3 A---C

2022-07-08 02:04:00 51CTO


A

#797div3 A---C_i++




Code :

      
      
/*
It's the champion , The bronze , The platform of the runner up . Middle high , Lower the left , The lowest on the right
1 The platform must be higher than 2 platform ,2 Must be higher than 3
3 Both platforms should be larger than 0( At least one

Purpose : Give total n, Ask the middle one to be as small as possible . Output any one

*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 5;

void s(){
int n;
cin >> n;

int a,b,c;
for(int i = 1; i <= n ;i ++){
if(i-1>0&&i>0&&n-2*i+1>0){// structure a = i -1; b = i; c = n - a - b
a = i - 1;
b = i;
c = n-2*i+1;

if(a > c && c > 0){
break;
}
}
}

for(int i = 1; i <= n; i++){
if(a-1>c+2){// Adjust here c, Give Way c Try to rise up
a-=1, b-=1;
c+=2;
}else if(a == c){// A special judge 2 3 2; Output is 2 4 1 Examples
c-=1,b+=1;
}
}
cout <<a << " " << b << " " << c << '\n';
}

int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif

int t; cin >> t;
while(t--) s();

return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.




B

#797div3 A---C_i++_02




Code :

      
      
#define LOCAL
/*

Two positive arrays a,b
It can be operated countless times a Array :
Every non-zero element -1

Purpose : Determine whether you can get an array b, Make every element equal

*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5, INF = 1e9 + 5;

int data[maxn], data2[maxn];

void s(){
int n ; cin >> n;

int maxone = -INF, sp = 0;
for(int i = 1;i <= n;i ++){
cin >> data[i];
if(data[i] > maxone) maxone = data[i], sp = i;// Find a maximum
}

for(int i = 1; i <= n; i++) cin >> data2[i];

int chazhi = maxone - data2[sp];
if(chazhi < 0) {// If the difference is negative , Just no
cout << "NO\n";
return;
}

for(int i = 1; i <= n ; i ++){
int tmp = (data[i] - chazhi >= 0 ? data[i] - chazhi : 0 );// You can merge and write , Just judge whether 0 Or make the difference equal
if(data2[i] != tmp) {
cout << "NO\n";
return;
}
}
cout << "YES\n";

}

int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t; cin >> t;
while(t--) s();


return 0;
}


  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.






C

#797div3 A---C_i++_03




Code :

      
      
#define LOCAL
/*
complete n A mission :

The first i Time s Yes, I know. . No two tasks are at the same time

The first i personal f, It is the time point when the task is completed

I don't know the duration of the task

It is said that , Tasks are completed on a first come, first served basis

Once you come to the first task , It's going to be implemented
If a task arrives when the previous task has not been completed , Just put the new task at the end of the queue and wait
If he finishes , You are about to perform the next task and the queue is not empty , He immediately took the team leader element . Wait before the task comes

Purpose : Find out how long each task has been performed

*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;

struct per{
int s, f;
} data[maxn];


void s(){
int n ; cin >> n;

for(int i = 1; i <= n; i++) cin >> data[i].s;
for(int i = 1; i <= n; i++) cin >> data[i].f;

int nowtime = 0;

for(int i = 1 ; i <= n; i++){// Simulate a task processing process
if(nowtime < data[i].s) nowtime = data[i].s;// The current time can jump , If you have to wait , Then jump directly to the beginning

if(data[i].f - nowtime > 0){// If there is still a long life span for this task , Just output the answer
cout << data[i].f - nowtime <<" ";

}
else if(data[i].f - nowtime <= 0){// If this task is out of date , It outputs 0
cout << 0 << " ";

}
nowtime = data[i].f;// Update the current time to finish the current task
}
cout <<'\n';

}


int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while(t--) s();


return 0;
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/189/202207080033383096.html