UPC 2017 Summer Training 5

来源:互联网 发布:淘宝服装类目售后期限 编辑:程序博客网 时间:2024/06/05 09:05

H - Another Square in the Floor

 Gym - 101086H 


While planning the SCPC2015 contest floor, each team has been assigned an area of a rectangular shape. The area covers the maximum region the team is allowed to move around during the contest.

When Noura saw the contest floor, she didn't like the rectangular shapes. She asked the organizers to reassign each team for a square shaped area instead of a rectangular one.

Given the sides of a rectangle, help the organizers find the square with minimum area, that covers the rectangle. To make it easier for the organizers, each side of the square must be parallel to one of the sides of the rectangle.

Input

The first line of input contains an integer T (1 ≤ T ≤ 1024), the number of test cases.

Each test case contains two space-separated integers XY (1 ≤ X, Y ≤ 1000), the dimensions of the rectangular shaped area.

Output

For each test case, print on a single line, the area of the square described in the problem statement.

Example
Input
33 35 712 6
Output
949144
Note

Warning: large Input/Output data, be careful with certain languages.



ac代码






























#include <cstdio>#include <cmath>#include <cstring>#include <stack>#include <algorithm>#define inf 0x3f3f3f3fusing namespace std;int t,x,y;int main(){scanf("%d",&t);while(t--){scanf("%d%d",&x,&y);int tmp=max(x,y);printf("%d\n",tmp*tmp);} return 0;}


G - Paradise City

 Gym - 101086G 

Noura has been looking for a restaurant to host the SCPC2015 celebration in Lattakia, she decided that the best method to pick a restaurant is according to the number of contestants that are living near it. Given a grid representing the map of Lattakia, each 3x3 cells represent a district, each district will consist of 3x3 areas. The center of each district is a restaurant (X), other cells can be:

  ‘.’ denotes an empty block.  ‘*’ denotes a block full of people (4 persons)
Help Noura decide which restaurant to choose by finding the maximum number of students living in a district.
Input

The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 100), the number of districts. Then follows three lines, each consists of 3 × N characters, representing the map of the city of N districts.

Output

For each test case, print the maximum number of students living in a district on a single line.

Example
Input
33***...***.X.*X*.X.***...***2*.*.*..X..X**.*.*.3.*...*****X**X**X*...*..*.*
Output
241628
Note

Warning: large Input/Output data, be careful with certain languages.



#include <cstdio>#include <cmath>#include <cstring>#include <stack>#include <algorithm>#define ll long long#define inf 0x3f3f3f3fusing namespace std;int t,n,a[3005];char MAP[50][3005];int main(){scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<3;i++){scanf("%s",MAP[i]);}memset(a,0,sizeof(a));int N=3*n;for(int i=0;i<3*N;i++){for(int j=0;j<3;j++){if(MAP[j][i]=='*')a[i]++;}}ll mmax=0;for(int i=0;i<N-2;i=i+3){ll ans=4*(a[i]+a[i+1]+a[i+2]);if(ans > mmax)mmax=ans;}printf("%I64d\n",mmax);} return 0;}

L - Chance

 Gym - 101086L 






After Noura's brother, Tamim, finished his junior training, coach Fegla was impressed with his progress. He told Noura that if Tamim would solve the following problem in SCPC2015 and yet does not qualify to the ACPC2015, he will give him a chance to participate unofficially in it.

The problem goes as follows:

Given L and R, how many integers between them have a prime number of ones in their binary representation?

Can you help Tamim participate in the ACPC2015?

Input

The first line of input contains an integer T (1 ≤ T ≤ 105), the number of test cases.

Each test case will consist of two space - separated integers: L and R (0 ≤ L ≤ R ≤ 105).

Output

For each test case, print the number of integers between L and R that have a prime number of ones in their binary representation.

Example
Input
32 101 193 101
Output
61365
Note

Warning: large Input/Output data, be careful with certain languages.


#include <cstdio>#include <cmath>#include <cstring>#include <stack>#include <algorithm>#define ll long long#define inf 0x3f3f3f3fusing namespace std;const int maxn=1e5+10;int kk[maxn];int a[maxn];int p[maxn];int t,l,r;int ans[maxn];void INIT(){memset(a,0,sizeof(a));int num=0,i,j;for(i=2;i<100001;i++){if(!a[i])p[num++]=i;for(j=0;(j < num && i*p[j] < 100001);j++){a[i*p[j]]=1;if(!(i%p[j]))break;}}a[0]=1;a[1]=1;memset(kk,0,sizeof(kk));for(i=0;i<=100000;i++){int tmp_i=i;while(tmp_i){kk[i]=kk[i]+tmp_i%2;tmp_i=tmp_i/2;}}memset(ans,0,sizeof(ans));ans[0]=0;for(i=1;i<=100000;i++){if(!a[kk[i]]){ans[i]=ans[i-1]+1;}elseans[i]=ans[i-1];}}int main(){INIT();scanf("%d",&t);while(t--){scanf("%d%d",&l,&r);int flag=0;if(!a[kk[l]])flag=1;elseflag=0;int wwww=ans[r]-ans[l]+flag;if(wwww > 0)printf("%d\n",wwww);elseprintf("0\n");} return 0;}


A - My Friend of Misery

 Gym - 101086A 




After Noura's brother, Tamim, finished his junior training, coach Fegla was impressed with his progress. He told Noura that if Tamim would solve the following problem in SCPC2015 and yet does not qualify to the ACPC2015, he will give him a chance to participate unofficially in it.

The problem goes as follows:

Given L and R, how many integers between them have a prime number of ones in their binary representation?

Can you help Tamim participate in the ACPC2015?

Input

The first line of input contains an integer T (1 ≤ T ≤ 105), the number of test cases.

Each test case will consist of two space - separated integers: L and R (0 ≤ L ≤ R ≤ 105).

Output

For each test case, print the number of integers between L and R that have a prime number of ones in their binary representation.

Example
Input
32 101 193 101
Output
61365
Note

Warning: large Input/Output data, be careful with certain languages.


With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind enough to transfer her own credit for the sake of keeping Noura online 24/7.

The phone credit transfer system in Syria works in the following way: Each successful transfer operation withdraws 25 extra credit units from the sender's balance, but it doesn't cost anything when a transfer operation is unsuccessful due to non sufficient credit balance.

Given the log of credit transfer requests and the response from the system to each request, in the form: Amount of transfer, and result of operation (either successful or unsuccessful), can you find out the number of possible initial credit balance values that Nicole could have had which satisfy the given log file?

Note that the initial credit balance is always a non negative integer.

Input

The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105), the number of operations in the log of credit transfer requests.

Each of the following N lines contains an integer mi (1 ≤ mi ≤ 106), the amount of credit to transfer, followed by .

  • { + } denotes a successful operation.
  • { - } denotes an unsuccessful operation.

Each log contains at least one unsuccessful operation.

Output

For each test case, print a single line that contains the number of possible initial credit balance values that Nicole could have had.

Example
Input
33512 -128 +256 +480 +70 +200 -150 +3100 -100 -540 -
Output
10350125
Note

Warning: large Input/Output data, be careful with certain languages.


#include <cstdio>#include <cmath>#include <cstring>#include <stack>#include <algorithm>#define ll long long#define inf 1e18+5using namespace std;const int maxn=1e5+10;int t,n;struct node{ll mon;char s[2];}nn[maxn];int main(){scanf("%d",&t);while(t--){scanf("%d",&n);ll mmax=inf;ll mmin=0;ll tmp=0;for(int i=1;i<=n;i++){scanf("%d%s",&nn[i].mon,nn[i].s);if(nn[i].s[0]=='-'){mmax=min(mmax,tmp+nn[i].mon+24);}else if(nn[i].s[0]=='+'){tmp+=nn[i].mon+25;mmin=max(mmin,tmp);}}printf("%I64d\n",mmax-mmin+1);} return 0;}



After Noura's brother, Tamim, finished his junior training, coach Fegla was impressed with his progress. He told Noura that if Tamim would solve the following problem in SCPC2015 and yet does not qualify to the ACPC2015, he will give him a chance to participate unofficially in it.

The problem goes as follows:

Given L and R, how many integers between them have a prime number of ones in their binary representation?

Can you help Tamim participate in the ACPC2015?

Input

The first line of input contains an integer T (1 ≤ T ≤ 105), the number of test cases.

Each test case will consist of two space - separated integers: L and R (0 ≤ L ≤ R ≤ 105).

Output

For each test case, print the number of integers between L and R that have a prime number of ones in their binary representation.

Example
Input
32 101 193 101
Output
61365
Note

Warning: large Input/Output data, be careful with certain languages.

原创粉丝点击