Codeforces 1260

DEF 题对于 wyh 来说过于毒瘤,十分不可做。

A. Heating

Description:

给定\(a,b\),将\(b\)分成至少\(a\)个正整数,使这些正整数的平方和最小。

Solution:

sb题,3minA掉,但是提交代码花了我近20min

Code:


#include<iostream>
#include<cstdio>
#include<cstring>
 
using namespace std;
 
typedef long long ll;
int T;
int a,b; 
 
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&a,&b);
        if(a>b){printf("%d\n",b);continue;}
        int ans=(b%a)*(b/a+1)*(b/a+1)+(a-b%a)*(b/a)*(b/a);
        printf("%d\n",ans);
    }
    return 0;
}

B. Obtain Two Zeroes

Description:

给定\(a,b\)和两种变化规则:

\[a=a−x , b=b−2x \]

\[ a=a−2x , b=b−x\]

问能不能将\(a,b\)都变成0

Solution:

对 mod 3 余数讨论即可。

Code:


#include<iostream>
#include<cstdio>
#include<cstring>
 
using namespace std;
 
typedef long long ll;
ll T;
ll a,b; 
 
int main()
{
    cin>>T;
    while(T--)
    {
        cin>>a>>b;
        if(a>b) swap(a,b);
        if((a*2-b)%3||a*2<b) printf("NO\n");
        else printf("YES\n");
        
    }
    return 0;
}

C. Infinite Fence

Description:

给定\(a,b,k\),将a的倍数涂成红色,b的倍数涂成蓝色,a和b的公倍数随便涂,问是否存在一种方案,使得将涂色的数字从小到大排序后,不存在连续k个数是同一种颜色。

Solution:

结论:将\(a\)\(b\)同除以\(gcd(a,b)\),结果不变。

这样我们就可以使\(a,b\)互质。假设\(a<=b\),然后判断啊\(a*(k-1)+1\)\(b\)的关系就行了。具体见代码。

Code:


#include<iostream>
#include<cstdio>
 
using namespace std;
 
typedef long long ll;
ll T,r,b,k;
 
ll gcd(ll a,ll b)
{
    if(!b) return a;
    return gcd(b,a%b);
}
 
int main()
{
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld%lld%lld",&r,&b,&k);
        ll g=gcd(r,b);r/=g;b/=g;if(r>b) swap(r,b);
        if(r*(k-1)+1>=b) printf("OBEY\n");
        else printf("REBEL\n");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/oierwyh/p/11965095.html