Educational Codeforces Round 77 (Rated for Div. 2)

A. Heating

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.

Your house has n rooms. In the i-th room you can install at most ci heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k2 burles.

Since rooms can have different sizes, you calculated that you need at least sumi sections in total in the i-th room.

For each room calculate the minimum cost to install at most ci radiators with total number of sections not less than sumi.

Input
The first line contains single integer n (1≤n≤1000) — the number of rooms.

Each of the next n lines contains the description of some room. The i-th line contains two integers ci and sumi (1≤ci,sumi≤104) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.

Output
For each room print one integer — the minimum possible cost to install at most ci radiators with total number of sections not less than sumi.

Example
inputCopy
4
1 10000
10000 1
2 6
4 6
outputCopy
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it’s optimal to use the radiator with sum1 sections. The cost of the radiator is equal to (104)2=108.

In the second room, you can install up to 104 radiators, but since you need only one section in total, it’s optimal to buy one radiator with one section.

In the third room, there 7 variants to install radiators: [6,0], [5,1], [4,2], [3,3], [2,4], [1,5], [0,6]. The optimal variant is [3,3] and it costs 32+32=18.

题意:n组测试数据
每组测试数据可以理解为求解 把sum最多分成c个数相加 使得这c份的每个数平方和最小
思路:很容易可以得出
c为1时 答案就是sum的平方
c大于sum时 答案就是 sum(即1的平方+1的平方+…+1的平方)
其它的情况就尽量分成 sum/csum/c+1
题解:代码就贴比赛时的代码了

#include<bits/stdc++.h>
using namespace std;
long long n,t,c,sum;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>c>>sum;
        long long ans=0;
        if(c==1)
        {
            ans+=sum*sum;
        }
        else if(c>=sum)
        {
            ans+=sum;
        }
        else
        {
            long long g=sum%c;
            long long h=sum/c;
            ans+=h*h*(c-g)+(h+1)*(h+1)*g;
        }
        cout<<ans<<endl;
    }
    return 0;
}

B. Obtain Two Zeroes

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given two integers a and b. You may perform any number of operations on them (possibly zero).

During each operation you should choose any positive integer x and set a:=a−x, b:=b−2x or a:=a−2x, b:=b−x. Note that you may choose different values of x in different operations.

Is it possible to make a and b equal to 0 simultaneously?

Your program should answer t independent test cases.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases.

Then the test cases follow, each test case is represented by one line containing two integers a and b for this test case (0≤a,b≤109).

Output
For each test case print the answer to it — YES if it is possible to make a and b equal to 0 simultaneously, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example
inputCopy
3
6 9
1 1
1 2
outputCopy
YES
NO
YES
Note
In the first test case of the example two operations can be used to make both a and b equal to zero:

choose x=4 and set a:=a−x, b:=b−2x. Then a=6−4=2, b=9−8=1;
choose x=1 and set a:=a−2x, b:=b−x. Then a=2−2=0, b=1−1=0.
题意 t组测试数据
对于每组测试数据 a和b 可以进行如下操作
a:=a−x , b:=b−2x 或 a:=a−2x, b:=b−x.
问你能否经过多次操作使得a和b都变成0
思路:首先排除0的情况和**min(a,b)乘2小于max(a,b)**的情况
其它的情况可以思考对于其它的情况 就是非上述情况
如果可以变为0 就也一定可以从0再加回原数 a 和 b
(每次a+1,b+2)或(a+2,b+1)一定可以凑出其它情况的a和b
然后观察可以得出 (a+b)%3是一定为零的 否则无法同时变为0
题解:

#include<bits/stdc++.h>
using namespace std;
long long t,a,b;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        if(a>b)swap(a,b);
        if(a==0&&b==0)cout<<"YES\n";
        else if(a==0||b==0)cout<<"NO\n";
        else
        {
            if(a*2<b||(a+b)%3!=0)cout<<"NO\n";
            else
            {
                cout<<"YES\n";
            }
        }
    }
    return 0;
}

C. Infinite Fence

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.

You must paint a fence which consists of 10100 planks in two colors in the following way (suppose planks are numbered from left to right from 0):

if the index of the plank is divisible by r (such planks have indices 0, r, 2r and so on) then you must paint it red;
if the index of the plank is divisible by b (such planks have indices 0, b, 2b and so on) then you must paint it blue;
if the index is divisible both by r and b you can choose the color to paint the plank;
otherwise, you don’t need to paint the plank at all (and it is forbidden to spent paint on it).
Furthermore, the Government added one additional restriction to make your punishment worse. Let’s list all painted planks of the fence in ascending order: if there are k consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don’t paint the fence according to the four aforementioned conditions, you will also be executed.

The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.

Input
The first line contains single integer T (1≤T≤1000) — the number of test cases.

The next T lines contain descriptions of test cases — one per line. Each test case contains three integers r, b, k (1≤r,b≤109, 2≤k≤109) — the corresponding coefficients.

Output
Print T words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.

Example
inputCopy
4
1 1 2
2 10 4
5 2 3
3 2 2
outputCopy
OBEY
REBEL
OBEY
OBEY
题意:t组数据
每组数据r,b,k
在区间[0,10^100]上
r表示 0,r , 2r , 3r ,…要染成同一颜色(忘记什么颜色了,就红色吧)
b表示 0,b , 2b , 3b ,…要染成同一颜色(蓝色)
如果某个数既可以染成红色也可以染成蓝色,那么就可以自己选择颜色 (必须染色,不可以不染)
然后问你染完颜色后把无色的去掉能否染成没有连续k个相同颜色在一起的
思路 刚开始一想,这题gcd,可是就是不知道怎么写,就一直拖,最后几分钟这道题被我暴力卡过去了估计会被hack
下面贴个大佬的代码(思路比较清晰看完之后基本就会了)
求两个数gcd 如果a>b a和b交换值 然后 a/=gcd b/=gcd 去掉两边除上a如果>=k 即区间中连续出现k个a 除完后 b-1是因为a的倍数距离k*b的最近距离为1 然后判断剩下的区间会不会有连续k个a
题解:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,k;
        cin>>a>>b>>k;
        int g=__gcd(a,b);
        a/=g;
        b/=g;
        if(a>b)swap(a,b);
        if((b-1+a-1)/a>=k)printf("REBEL\n");
        else printf("OBEY\n");
    }
}

额 现在已经被hack了 我太难了 明天补题 晚安

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值