Gym 101086 A, L ,G,H ,F 题解

A. My Friend of Misery
time limit per test
3.0 s
memory limit per test
256 MB
input
standard input
output
standard output

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.

Examples
input
3
3
512 -
128 +
256 +
4
80 +
70 +
200 -
150 +
3
100 -
100 -
540 -
output
103
50
125

123

题意: 求 可能的钱数种类,  +交易成功, - 交易失败,  成功需要支付手续费25

找失败最小的的金额+25,成功总额加起来, 是最低金额

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int INF=1<<30;
int main()
{
	int T;
	int n,x;
	cin>>T;
	char str[3];
	while(T--)
	{
		
		scanf("%d",&n);
        ll sum=0,le=0,sum2=1e13;
        while(n--)  
        {
            scanf("%d%s",&x,&str);
            if(str[0]=='+')
			{
				sum+=x+25;
				le=sum;	
			}
            else sum2=min(sum2,sum+x+25);
        }
		printf("%lld\n",sum2-le);
	}
	
    return 0;
}



L

L. Chance
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

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.

Examples
input
3
2 10
1 19
3 101
output
6
13
65

题意是: 求 l-r 之间 二进制形式时 1 的个数是素数的 总数

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=1000005;

int a[N];
bool judge(int n)
{
	if(n<=1) return false;
	if(n==2) return true;
	for(int i=2;i<=sqrt(n);i++)
		if(n%i==0) return false;
	return true;
}
void init()
{
	a[0]=0;
	for(int i=1;i<=N;i++)
	{
		int temp=i;
		int cont=0;
		while(temp)
		{
			if(temp%2==1)
				cont++;
			temp/=2;
		}
		if(judge(cont))
			a[i]=a[i-1]+1;
		else
			a[i]=a[i-1];
	}
}
int main()
{
	int T;
	init();
	cin>>T;
	int x,y;
	while(T--)
	{
		scanf("%d %d",&x,&y);
		printf("%d\n",a[y]-a[x-1]);
	}
	
    return 0;
}


G-

G. Paradise City
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output

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 of3 × 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.

Examples
input
3
3
***...***
.X.*X*.X.
***...***
2
*.*.*.
.X..X*
*.*.*.
3
.*...****
*X**X**X*
...*..*.*
output
24
16
28

水题:  X 周围* 最多的是 哪个X 

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=1000011;

int main()
{
	int T;
	cin>>T;
	int n;
	string str;
	int a[300];
	while(T--)
	{
		scanf("%d",&n);
		str.clear();
		memset(a,0,sizeof(a));
		for(int i=0;i<3;i++)
		{
			cin>>str;
			int len=str.length();
			int cont=0,num=1,k=0;
			for(int j=0;j<len;j++)
			{
				if(str[j]=='*')
				{
					cont++;
				}	
				if(num%3==0)
				{
					a[k]+=cont;
					k++;
					cont=0;
				}
				num++;
				
			}
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
		//	printf("%d ",a[i]);
			ans=max(ans,a[i]);
		}
		printf("%d\n",ans*4);
	}
    return 0;
}


H-

H. Another Square in the Floor
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output

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 X, Y (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.

Examples
input
3
3 3
5 7
12 6
output
9
49
144


水题:   大的平方:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long ll;
const int N=1000011;

int main()
{
	int T;
	cin>>T;
	int x,y;
	while(T--)
	{
		scanf("%d %d",&x,&y);
		x=max(x,y);
		printf("%d\n",x*x);
	}
    return 0;
}



F-

F. Hey JUDgE
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Since Judge Nicole Hosh moved to Egypt for her Computer Science Masters in AASTMT, in 2014, she has been training with coach Fegla and attending his camps in Egypt. She, also, set a number of problems for TCPC and JCPC and was a judge in LCPC and SCPC. Her best friend Noura was so proud of her so she was trying to convince her to start writing Codeforces Div. 2 round. After various attempts to convince her, Nicole finally agreed, and so, she started collecting some problems with different difficulties from her ex-contestant friends.

Judge Nicole collected 7 ideas for problems of different levels, she wants to create 5 problems for the next contest, one for each difficulty level, from A to E (difficulty 1 to 5). Given the difficulty level of the problems she currently has, she can merge the ideas of two problems, one of level x, and the other of level y to get a problem of level x + y.

For example, Judge Nicole can merge two problems of difficulties A and D, to get one problem of difficulty E (1 + 4 = 5).

Merging more than two problems into one will produce a problem with a long statement which is hard to explain, so she won’t do this (i.e., each problem is merged with another at most once). Also, she can’t merge a resultant problem again, and she can't use the same problem twice.

Input

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

Each test case will contain only one string S of length 7. Each letter of the string represents the difficulty level of a problem (from A to E), 'A' is the easiest and 'E' is the hardest.

Output

For each test case print "YES" if she can prepare a contest using the current problems, otherwise print "NO".

Examples
input
3
EBEABDA
CEDEACA
BDAAEAA
output
YES
NO
YES

123

模拟组合  C(7,2) 和 C(7,4)

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <vector>
using namespace std;
typedef long long ll;
const double PI=acos(-1);  
const int INF=0x3f3f3f3f;  
const double esp=1e-6;  
const int maxn=100005;  
const int MOD=1e9+7;
#define mem(a,b) memset(a,b,sizeof(a))
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}


int main()
{
	int T;
	int n,x;
	cin>>T;
	string s;
	n=5;
	int num[6];
	while(T--)
	{
		cin>>s;
		memset(num,0,sizeof(num));
		for(int i=0;i<s.length();i++)
			num[s[i]-'A'+1]++;
		int flag,fflag;
		for(int i=1;i<=n;i++)
			if(!num[i]) flag=1;
		if(flag)
		{
			for(int i=0;i<7;i++)
				for(int j=i+1;j<7;j++)
				{
					int a=s[i]-'A'+1,b=s[j]-'A'+1;
					fflag=1;
					num[a]--;num[b]--;num[a+b]++;
					for(int ii=1;ii<=n;ii++)
						if(!num[ii]) fflag=0;
					if(fflag) flag=0;
					num[a]++;num[b]++;num[a+b]--;
				}
			if(flag)
			{
				for(int i=0;i<7;i++)
					for(int j=i+1;j<7;j++)
						for(int ii=0;ii<7;ii++)
							for(int jj=ii+1;jj<7;jj++)
							{
								if(i!=ii&&i!=jj&&j!=ii&&j!=jj)
								{
									int a=s[i]-'A'+1,b=s[j]-'A'+1,c=s[ii]-'A'+1,d=s[jj]-'A'+1;
									fflag=1;
									num[a]--,num[b]--,num[c]--,num[d]--;
									num[a+b]++,num[c+d]++;
									for(int k=1;k<=n;k++)
										if(!num[k]) fflag=0;
									if(fflag) flag=0;
									num[a]++,num[b]++,num[c]++,num[d]++;
									num[a+b]--,num[c+d]--;
								}
							}
			}
			
		}
		if(!flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	
    return 0;
}


posted @ 2017-08-17 08:27  Sizaif  阅读(449)  评论(0编辑  收藏  举报