codeforces#525 Div2---ABC

A---Ehab and another constriction problem

https://codeforc.es/contest/1088/problem/A

题意:给定一个数$x$找两个在$1$~$x$之间的数$a$和$b$,$b$是$a$的因子,$a*b > x, frac{a}_{b} < x$

思路:两个数都选$x$自己就可以了。在$x=1$的时候因为要求中不包含等号,所以是找不到这样的数的。

 1 #include<iostream>
 2 //#include<bits/stdc++.h>
 3 #include<cstdio>
 4 #include<cmath>
 5 //#include<cstdlib>
 6 //#include<cstring>
 7 //#include<algorithm>
 8 //#include<queue>
 9 //#include<vector>
10 //#include<set>
11 //#include<climits>
12 //#include<map>
13 using namespace std;
14 typedef long long LL;
15 typedef unsigned long long ull;
16 #define pi 3.1415926535
17 #define inf 0x3f3f3f3f
18 
19 int x;
20 
21 int main()
22 {
23     while(scanf("%d", &x)!= EOF){
24 
25         if(x == 1){
26             printf("-1
");
27         }
28         else{
29             printf("%d %d
", x, x);
30         }
31         
32     }
33     return 0;
34 }
View Code

B---Ehab and substraction

https://codeforc.es/contest/1088/problem/B

题意:给定一个序列,每次找到非零的最小值,让剩下的所有非零的数减去他。输出$k$次操作每次选择的这个数。

思路:用一个优先队列维护一下就可以了。然后用一个变量记录总的减掉的总值。

 1 #include<iostream>
 2 //#include<bits/stdc++.h>
 3 #include<cstdio>
 4 #include<cmath>
 5 //#include<cstdlib>
 6 //#include<cstring>
 7 #include<algorithm>
 8 #include<queue>
 9 //#include<vector>
10 //#include<set>
11 //#include<climits>
12 //#include<map>
13 using namespace std;
14 typedef long long LL;
15 typedef unsigned long long ull;
16 #define pi 3.1415926535
17 #define inf 0x3f3f3f3f
18 
19 int n, k;
20 const int maxn = 1e5 + 5;
21 int num[maxn];
22 
23 
24 int main()
25 {
26     while(scanf("%d%d", &n, &k) != EOF){
27         priority_queue<int, vector<int>, greater<int> >que;
28         int mx = -1;
29         for(int i = 0; i < n; i++){
30             scanf("%d", &num[i]);
31             mx = max(mx, num[i]);
32             que.push(num[i]);
33         }
34 
35         LL sub = 0;
36         for(int i = 0; i < k; i++){
37             if(que.empty())printf("0
");
38             else{
39                 int now = que.top();
40                 que.pop();
41                 now -= sub;
42                 while(!now && !que.empty()){
43                     now = que.top();
44                     que.pop();
45                     now -= sub;
46                 }
47                 printf("%d
", now);
48                 sub += (LL)now;
49             }
50         }
51     }
52     return 0;
53 }
View Code

C---Ehab and a 2-operation task【思维好题】

https://codeforc.es/contest/1088/problem/C

题意:

给定一个序列

操作1,选定一个下标$i$,和一个数$x$,对$1$~$i$的每一个数都加上$x$

操作2,选定一个下标$i$,和一个数$x$, 对$1$~$i$的每一个数都取模$x$

最多执行n+1次操作,使得最后的序列是递增的

思路:

用到了一些取模的性质,不太熟所以没想到。

如果有$a<b$,那么$a % b = a$

如果有$a > b > a /2$,那么有$a % b = a - b$

现在要让他是递增的序列,只需要让第$i$个数是$i$就可以了。假设第$i$数是$num[i]$,只需要执行$num[i] % (num[i] - i)$

所以首先给每一个数加上一个很大的数,比如$1e5 + 5$

然后从前往后对他们取模,连负数都不需要考虑。

 1 #include<iostream>
 2 //#include<bits/stdc++.h>
 3 #include<cstdio>
 4 #include<cmath>
 5 //#include<cstdlib>
 6 //#include<cstring>
 7 #include<algorithm>
 8 #include<queue>
 9 //#include<vector>
10 //#include<set>
11 //#include<climits>
12 //#include<map>
13 using namespace std;
14 typedef long long LL;
15 typedef unsigned long long ull;
16 #define pi 3.1415926535
17 #define inf 0x3f3f3f3f
18 
19 int n;
20 const int maxn = 2005;
21 const int add = 1e5 + 5;
22 LL num[maxn];
23 
24 
25 int main()
26 {
27     while(scanf("%d", &n) != EOF){
28         for(int i = 0; i < n; i++){
29             scanf("%lld", &num[i]);
30             num[i] += add;
31         }
32 
33         LL sub = 0;
34         printf("%d
", n + 1);
35         printf("1 %d %d
", n, add);
36         for(int i = 0; i < n; i++){
37             printf("2 %d %lld
", i + 1, num[i] - i);
38         }
39     }
40     return 0;
41 }
View Code
原文地址:https://www.cnblogs.com/wyboooo/p/10105252.html