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

来源:互联网 发布:求五轴磨床编程软件 编辑:程序博客网 时间:2024/06/11 00:43

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
33512 -128 +256 +480 +70 +200 -150 +3100 -100 -540 -
output
10350125

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
32 101 193 101
output
61365

题意是: 求 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;elsea[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
33***...***.X.*X*.X.***...***2*.*.*..X..X**.*.*.3.*...*****X**X**X*...*..*.*
output
241628

水题:  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
33 35 712 6
output
949144


水题:   大的平方:

#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
3EBEABDACEDEACABDAAEAA
output
YESNOYES

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");elseprintf("NO\n");}    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电脑开机时不显示用户名怎么办? xp系统忘记开机密码怎么办 电脑开机密码忘了怎么办 c盘满了怎么办win10 win10电脑开机密码忘了怎么办 win10的开机密码忘了怎么办 u盘中了exe病毒怎么办 眼睛长个麦粒豆怎么办 苹果手机sdk授权失败怎么办 小米5王者荣耀卡怎么办 华为p9手机电池不耐用怎么办 华为g9青春版耗电快怎么办 华为手机摄像头坏了怎么办 华为p10摄像头玻璃划痕怎么办? 华为g9手机音量小怎么办 华为7pius太卡怎么办 华为畅享7plus卡怎么办 华为p9屏幕进水变颜色怎么办? 玩王者荣耀卡退怎么办 华为手机忘记开机密码怎么办 华为p9密码忘了怎么办 华为p9解锁密码忘了怎么办 华为手机不支持联通4g怎么办 酷派手机自动下载软件怎么办 小米5a不能开机怎么办 华为手机的视频找不到了怎么办 华为p8内存文件打不开怎么办 华为荣耀9网速慢怎么办 荣耀9手机网速慢怎么办 联想台式机不支持xp驱动怎么办 一体机尾插坏了怎么办 华为手机触屏失灵怎么办 华为p8max手机老是卡怎么办 手机屏碎了数据怎么办 华为p9屏碎了怎么办 华为p7一l09卡顿怎么办 华为p7打不开机怎么办 华为8主板坏了怎么办 华为手机主板坏了怎么办 华为p9文字变英文了怎么办 华为p9plus电池不耐用怎么办