UPC 2017 Summer Training 5

来源:互联网 发布:c语言字符串指针传递 编辑:程序博客网 时间:2024/06/04 20:02

A - My Friend of Misery

 

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.


此题有毒,不过光卡long long int,还卡0x3f3f3f3f

此题问的是可能还剩余多少钱,‘-’表示提取失败,‘+’表示提取成功,提取成功需要手续费25;

思路:先找到第一个提取失败的操作,该操作的费用加上25(表示原来可能存在的钱数,操作失败可以变相的看成恰好成功)用变量ans保存,ans减去操作成功的费用和25,在与下一次操作失败的费用比较取最小值。


代码如下:

#include<iostream>#include<stdio.h>#include<algorithm>#define INF 1e18typedef long long int ll;using namespace std;int main(){    ll t,n;    ll num;    char str;    scanf("%lld",&t);    while(t--)    {        scanf("%lld",&n);        ll ans=INF;        for(ll i=0;i<n;i++)        {            scanf("%lld %c",&num,&str);            if(str=='-')                ans=min(ans,num+25);            else                ans-=(num+25);        }        if(ans<=0)            printf("0\n");        else            printf("%lld\n",ans);    }    return 0;}


G - Paradise City

 

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


水题

代码如下:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<string.h>const int N=103;using namespace std;int main(){    int t;    int n;    scanf("%d",&t);    char str[4][350];    while(t--)    {        scanf("%d",&n);        for(int i=0;i<3;i++)            scanf("%s",&str[i]);        int ant=0;        for(int i=0;i<3*n;i++)        {            if(str[1][i]=='X')            {                int ans=0;                if(str[1][i-1]=='*'&&i-1>=0)                    ans++;                if(str[1][i+1]=='*'&&i+1<3*n)                    ans++;                if(str[0][i-1]=='*'&&i-1>=0)                    ans++;                if(str[0][i]=='*')                    ans++;                if(str[0][i+1]=='*'&&i+1<3*n)                    ans++;                if(str[2][i-1]=='*'&&i-1>=0)                    ans++;                if(str[2][i]=='*')                    ans++;                if(str[2][i+1]=='*'&&i+1<3*n)                    ans++;                ant=max(ant,ans);            }        }        printf("%d\n",4*ant);    }    return 0;}

H - Another Square in the Floor

 

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

又是一道水题

代码如下:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>using namespace std;int main(){    int t;    int a,b;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&a,&b);        printf("%.0lf\n",pow( max(a,b),2 ));    }    return 0;}


L - Chance

 

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

题意:判断L到R中二进制1的个数是素数的有几个,需要打表(不然会超时)

代码如下:

#include<iostream>#include<stdio.h>#include<cmath>#include<string.h>int visit[]={0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1};int bit[100006]={0};using namespace std;int BitCount1(int n){    int count =0 ;    while(n)    {        count++;        n=(n-1)&n;    }    return count;}int main(){    int t,l,r,ant;    for(int i=1;i<100004;i++)    {        if(visit[BitCount1(i)])            bit[i]=bit[i-1]+1;        else            bit[i]=bit[i-1];    }    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&l,&r);        ant=0;        printf("%d\n",bit[r]-bit[l-1]);    }    return 0;}















原创粉丝点击