A. Heating
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1a836e0f7b71fea47773b1d194bec67e.png)
题目大意:就是给你一个数n把它分成k份始得每一份的平方和最小;
思路:1.如果k足够大那么将n分成n个1平方和为n是最小的
2.如果k < n,我们还是从第一点出发,先将n拆成n个1,然后再平均分配给k个位置
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <queue>
#include <algorithm>
#define MEM(a,al) memset(a,al,sizeof(a))
#define sfx(x) scanf("%lf",&x)
#define sfxy(x,y) scanf("%lf%lf",&x,&y)
#define sdx(x) scanf("%d",&x)
#define sdxy(x,y) scanf("%d%d",&x,&y)
#define pfx(x) printf("%.0f\n",x)
#define pfxy(x,y) printf("%.6f %.6f\n",x,y)
#define pdx(x) printf("%d\n",x)
#define pdxy(x,y) printf("%d %d\n",x,y)
#define getArray(a,len) for(int ia = 0; ia < len; ia++) scanf("%d",&a[ia])
#define printArray(a,len) for(int ia = 0; ia < len; ia++) printf("%d%c",a[ia],(ia==len-1)?'\n':' ')
#define fora(i,n) for(i = 0; i < n; i++)
#define fora1(i,n) for(i = 1; i <= n; i++)
#define foraf(i,n) for(int i = 0; i < n; i++)
#define foraf1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(i = n-1; i >= 0; i--)
#define ford1(i,n) for(i = n; i > 0; i--)
#define fordf(i,n) for(int i = n-1; i >= 0; i--)
#define fordf1(i,n) for(int i = n; i > 0; i--)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define f first
#define s second
using namespace std;
const int N = 5e5 + 10;
typedef pair<int,int> PII;
typedef long long LL;
char a[N], Ma[N * 2];
int T, hash[N], ne[26], Mp[N * 2];
int main()
{
IOS;
int T;
cin >> T;
while(T --)
{
int c, s;
LL ans = 0;
cin >> c >> s;
if(s < c) cout << s << endl;
else
{
int eps = s / c;
int mod = s % c;
for(int i = 1; i <= c - mod; ++ i)
ans += 1ll * eps * eps;
for(int i = 1; i <= mod; ++ i)
ans += 1ll * (eps + 1) * (eps + 1);
cout << ans << endl;
}
}
return 0;
}
B. Obtain Two Zeroes
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fa02100cb8547f5e3299096e63789cd3.png)
题意:你被给予两个数a和b,你可以对这两个数进行操作 每次操作你可以选择任意的正整数x,可以进行a = a - x,b = b - 2x或者a = a - 2x,b = b - x两种操作 是否可以让两个整数同时变为0
假设a = x1 + x2 + … +xm + y1 + y2 + … yn;
那么b = 2*(x1 + x2 + x3 + … + xm) + (1 / 2) *(y1 + y2 + … + yn);
将b * 2 - a 的 (2*b - a) = (3的倍数) ;
所以这道题就出来了
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <queue>
#include <algorithm>
#define MEM(a,al) memset(a,al,sizeof(a))
#define sfx(x) scanf("%lf",&x)
#define sfxy(x,y) scanf("%lf%lf",&x,&y)
#define sdx(x) scanf("%d",&x)
#define sdxy(x,y) scanf("%d%d",&x,&y)
#define pfx(x) printf("%.0f\n",x)
#define pfxy(x,y) printf("%.6f %.6f\n",x,y)
#define pdx(x) printf("%d\n",x)
#define pdxy(x,y) printf("%d %d\n",x,y)
#define getArray(a,len) for(int ia = 0; ia < len; ia++) scanf("%d",&a[ia])
#define printArray(a,len) for(int ia = 0; ia < len; ia++) printf("%d%c",a[ia],(ia==len-1)?'\n':' ')
#define fora(i,n) for(i = 0; i < n; i++)
#define fora1(i,n) for(i = 1; i <= n; i++)
#define foraf(i,n) for(int i = 0; i < n; i++)
#define foraf1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(i = n-1; i >= 0; i--)
#define ford1(i,n) for(i = n; i > 0; i--)
#define fordf(i,n) for(int i = n-1; i >= 0; i--)
#define fordf1(i,n) for(int i = n; i > 0; i--)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define f first
#define s second
using namespace std;
const int N = 5e5 + 10;
typedef pair<int,int> PII;
typedef long long LL;
char a[N], Ma[N * 2];
int T, hash[N], ne[26], Mp[N * 2];
int main()
{
IOS;
int T;
cin >> T;
while(T --)
{
int c, s;
LL ans = 0;
cin >> c >> s;
if(c > s) swap(c,s);
if((2*c-s) % 3 == 0 && (2 * c >= s)) puts("YES");
else puts("NO");
}
return 0;
}
C. Infinite Fence
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e9a34cf3f6d823e896bc6e39d0657df5.png)
现有10^100块木板需要涂漆,第x块如果是x是a的倍数,则涂一种颜色,是b的倍数,则涂另一种颜色。如果既是a又是b的倍数,那么两种颜色都可以涂;如果连续有k块板的颜色是一样的,则会被处死,问是否能避免被处死。
思路很简单:假设a>b,如果有连续的k块b在[ay~a(y+1)]之间一定会死
假设在ay 这个位置涂red那么在ay + q上涂blue那么我们要求出q的最小值再去看一下间隔最大可以涂多少个blue,那么ay + q mod b == 0那么转化为方程就是(ay + q) = kx;
由裴蜀定理得
ay - kb = q这个方程最小值就是q = gcd(a,b);
那么max = (a - q - 1) / b + 1
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <queue>
#include <algorithm>
#define MEM(a,al) memset(a,al,sizeof(a))
#define sfx(x) scanf("%lf",&x)
#define sfxy(x,y) scanf("%lf%lf",&x,&y)
#define sdx(x) scanf("%d",&x)
#define sdxy(x,y) scanf("%d%d",&x,&y)
#define pfx(x) printf("%.0f\n",x)
#define pfxy(x,y) printf("%.6f %.6f\n",x,y)
#define pdx(x) printf("%d\n",x)
#define pdxy(x,y) printf("%d %d\n",x,y)
#define getArray(a,len) for(int ia = 0; ia < len; ia++) scanf("%d",&a[ia])
#define printArray(a,len) for(int ia = 0; ia < len; ia++) printf("%d%c",a[ia],(ia==len-1)?'\n':' ')
#define fora(i,n) for(i = 0; i < n; i++)
#define fora1(i,n) for(i = 1; i <= n; i++)
#define foraf(i,n) for(int i = 0; i < n; i++)
#define foraf1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(i = n-1; i >= 0; i--)
#define ford1(i,n) for(i = n; i > 0; i--)
#define fordf(i,n) for(int i = n-1; i >= 0; i--)
#define fordf1(i,n) for(int i = n; i > 0; i--)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define f first
#define s second
using namespace std;
const int N = 5e5 + 10;
typedef pair<int,int> PII;
typedef long long LL;
char a[N], Ma[N * 2];
int T, hash[N], ne[26], Mp[N * 2];
int main()
{
IOS;
int T;
cin >> T;
while(T --)
{
LL r, b, k;
cin >> r >> b >> k;
if(b < r) swap(r,b);
LL cl = b - __gcd(r,b) - 1;
LL x = 1 + cl / r;
if(x < k) puts("OBEY");
else puts("REBEL");
}
return 0;
}