time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 nn rooms. In the ii-th room you can install at most cici heating radiators. Each radiator can have several sections, but the cost of the radiator with kk sections is equal to k2k2 burles.
Since rooms can have different sizes, you calculated that you need at least sumisumi sections in total in the ii-th room.
For each room calculate the minimum cost to install at most cici radiators with total number of sections not less than sumisumi.
Input
The first line contains single integer nn (1≤n≤10001≤n≤1000) — the number of rooms.
Each of the next nn lines contains the description of some room. The ii-th line contains two integers cici and sumisumi (1≤ci,sumi≤1041≤ci,sumi≤104) — the maximum number of radiators and the minimum total number of sections in the ii-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most cici radiators with total number of sections not less than sumisumi.
Example
input
Copy
4
1 10000
10000 1
2 6
4 6
output
Copy
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum1sum1 sections. The cost of the radiator is equal to (104)2=108(104)2=108.
In the second room, you can install up to 104104 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 77 variants to install radiators: [6,0][6,0], [5,1][5,1], [4,2][4,2], [3,3][3,3], [2,4][2,4], [1,5][1,5], [0,6][0,6]. The optimal variant is [3,3][3,3] and it costs 32+32=1832+32=18.
当时先做的B(f)题,B(f)题很难简单,是一个数学的移动问题,但是不想分类一点一点的讨论,就想了很久把他们总结了起来
#include <iostream>
using namespace std;
int main()
{
int t,a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b;
if(a>b)
{c=a;a=b;b=c;}
if((b-a)>a)
cout<<"NO"<<endl;
else
if((a+b)%3==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
因为要总结,所以用的时间很长。但是想出来之后又感觉很精髓,能够把他们相加除三,在以前是不可能想到的。
然后就陷入了闭环。总想着去把所有的题目总结成一个东西做出来,然后A题就怎么也看不出来了。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
int c,sum,ans=0;
cin>>c>>sum;
int tmp=sum/c;
if(sum%c==0)
ans=c*tmp*tmp;
else
ans=(c-sum%c)*tmp*tmp+(sum%c)*(tmp+1)*(tmp+1);
cout<<ans<<endl;
}
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two integers aa and bb. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer xx and set a:=a−xa:=a−x, b:=b−2xb:=b−2x or a:=a−2xa:=a−2x, b:=b−xb:=b−x. Note that you may choose different values of xx in different operations.
Is it possible to make aa and bb equal to 00 simultaneously?
Your program should answer tt independent test cases.
Input
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Then the test cases follow, each test case is represented by one line containing two integers aa and bb for this test case (0≤a,b≤1090≤a,b≤109).
Output
For each test case print the answer to it — YES if it is possible to make aa and bb equal to 00 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
input
Copy
3
6 9
1 1
1 2
output
Copy
YES
NO
YES
Note
In the first test case of the example two operations can be used to make both aa and bb equal to zero:
- choose x=4x=4 and set a:=a−xa:=a−x, b:=b−2xb:=b−2x. Then a=6−4=2a=6−4=2, b=9−8=1b=9−8=1;
- choose x=1x=1 and set a:=a−2xa:=a−2x, b:=b−xb:=b−x. Then a=2−2=0a=2−2=0, b=1−1=0b=1−1=0.
代码在上边
c题
D题
类似于游戏 有一些小兵,他们有一些敏捷值,通过面对一定数量陷阱淘汰低敏戒值,问多少小兵最后可以到达
E题
拳击比赛,人数对打,可以贿赂。这个题一点思路都没有。。