A:Yet Another Two Integers Problem
提议思路 : 两数之差除10向下取整即可
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int T;
cin >>T;
while(T--){
int a, b;
cin >> a >> b;
int c = abs(a-b);
int ans;
if(c % 10 == 0)
ans = c / 10;
else
ans = c / 10 + 1;
cout << ans <<endl;
}
}
B Minimum Produc
题意 : 对两数进行减一操作,条件:1操作次数 2两数最小值约束
思路 : 分别对两数进行减数操作与反向加数操作,取最小值
代码
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
int main(){
int T;
cin >>T;
while(T--){
LL a, b, x, y, n;
cin >> a >> b >>x >>y >>n;
LL A = abs(a - x);
LL B = abs(b - y);
LL ans1 = 0;
LL ans2 = 0;
LL nn = (A+B) - n;
if((A+B) <= n){
ans1 = x*y;
cout << ans1 <<endl;
continue;
}
if(x > y){
if(A >= nn){
ans1 = (x+nn)*y;
}
else{
ans1 = a*(y+(nn-A));
}
}
else if(x < y){
if(B >= nn){
ans1 = (y+nn)*x;
}
else{
ans1 = b*(x+(nn-B));
}
}
else if(x == y){
if(A >= B){
if(A >= nn){
ans1 = (x+nn)*y;
}
else{
ans1 = a*(y+(nn-A));
}
}
else{
if(B >= nn){
ans1 = (y+nn)*x;
}
else{
ans1 = b*(x+(nn-B));
}
}
}
//cout <<ans <<endl;
if(a < b){
if(A >= n)
ans2 = (a - n) * b;
else{
ans2 = x*(b-(n-A));
}
}
else if(a > b){
if(B >= n)
ans2 = (b - n) * a;
else{
ans2 = y*(a-(n-B));
}
}
else if(a == b){
if(A >= B){
if(A >= n)
ans2 = (a - n) * b;
else{
ans2 = x*(b-(n-A));
}
}
else{
if(B >= n)
ans2 = (b - n) * a;
else{
ans2 = y*(a-(n-B));
}
}
}
//cout << ans2 <<endl;
LL ans = min(ans1, ans2);
cout <<ans <<endl;
}
}
C. Yet Another Array Restoration
题意 : 给出数组元素数目与两个元素,要求构造等差数列,使最大值最小
思路 : 构造等差数列,要求两个元素 : 1 公差 2 初始元素
1 公差:必为给出的两元素之差的因数,且差值与公差的商必小于元素数目
2 初始元素:从最大元素向前减,若小于零,则取模
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int T;
cin >>T;
while(T--){
int n, x, y;
cin >> n >> x >> y;
int c = abs(x-y);
int gc = 0;
for(int i = n-1; i >= 1; i--){
if(c % i == 0){
gc = c / i;
break;
}
}
int zero = y - gc*(n-1);
if(zero <= 0)
zero = y % gc;
if(zero == 0)
zero = gc;
for(int i = 0; i < n; i++){
cout << zero + i*gc ;
if(i != n-1)
cout << ' ';
else cout <<endl;
}
}
}