标签:水
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whether a string in the shop contains all the beads she needs. She now comes to you for help: if the answer is "Yes", please tell her the number of extra beads she has to buy; or if the answer is "No", please tell her the number of beads missing from the string.
For the sake of simplicity, let‘s use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. For example, the 3rd string in Figure 1 is the one that Eva would like to make. Then the 1st string is okay since it contains all the necessary beads with 8 extra ones; yet the 2nd one is not since there is no black bead and one less red bead.
Input Specification:
Each input file contains one test case. Each case gives in two lines the strings of no more than 1000 beads which belong to the shop owner and Eva, respectively.
Output Specification:
For each test case, print your answer in one line. If the answer is "Yes", then also output the number of extra beads Eva has to buy; or if the answer is "No", then also output the number of beads missing from the string. There must be exactly 1 space between the answer and the number.
Sample Input 1:ppRYYGrrYBR2258 YrR8RrYSample Output 1:
Yes 8Sample Input 2:
ppRYYGrrYB225 YrR8RrYSample Output 1:
No 2
STL的简单应用
Code:
#include<cstdio> #include<cstring> #include<set> using namespace std; multiset<char> mst; char s1[1005],s2[1005]; int main() { while(scanf("%s%s",s1,s2)==2) { mst.clear(); bool flag=true; int cnt=0; int len1=strlen(s1); int len2=strlen(s2); for(int i=0;i<len1;i++) { mst.insert(s1[i]); } multiset<char>::iterator it; for(int i=0;i<len2;i++) { it=mst.find(s2[i]); if(it==mst.end()) { flag=false; cnt++; } else mst.erase(it); } if(flag) printf("Yes %d\n",mst.size()); else printf("No %d\n",cnt); } return 0; }B. Count PAT‘s (25)
时间限制120 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CAO, PengThe string APPAPT contains two PAT‘s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.
Now given any string, you are supposed to tell the number of PAT‘s contained in the string.
Input Specification:
Each input file contains one test case. For each case, there is only one line giving a string of no more than 105characters containing only P, A, or T.
Output Specification:
For each test case, print in one line the number of PAT‘s contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.
Sample Input:APPAPTSample Output:2
code:
#include<cstdio> #include<cstring> #define LL long long using namespace std; const int MOD=1000000007; const int N=1e5; char s[N+5]; int main() { while(scanf("%s",s)==1) { LL p=0; LL pa=0; LL pat=0; int len=strlen(s); for(int i=0;i<len;i++) { if(s[i]=='P') { p++; } if(s[i]=='A') { pa=pa+p; } if(s[i]=='T') { pat=pat+pa; } } printf("%d\n",pat%MOD); } return 0; }C. The Largest Generation (25)
时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueA family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.
Input Specification:
Each input file contains one test case. Each case starts with two positive integers N (<100) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (<N) which is the number of family members who have children. Then M lines follow, each contains the information of a family member in the following format:
ID K ID[1] ID[2] ... ID[K]
where ID is a two-digit number representing a family member, K (>0) is the number of his/her children, followed by a sequence of two-digit ID‘s of his/her children. For the sake of simplicity, let us fix the root ID to be 01. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.
Sample Input:23 13 21 1 23 01 4 03 02 04 05 03 3 06 07 08 06 2 12 13 13 1 21 08 2 15 16 02 2 09 10 11 2 19 20 17 1 22 05 1 11 07 1 14 09 1 17 10 1 18Sample Output:9 4
code:
#include<cstdio> #include<cstring> #include<queue> using namespace std; bool mat[105][105]; bool root[105]; int n,m; int R; int cnt[105]; int ans1,ans2; struct TNode { int num; int level; }; void BFS() { queue<TNode> Q; TNode first; first.num=R; first.level=1; TNode next; Q.push(first); while(!Q.empty()) { first=Q.front(); cnt[first.level]++; Q.pop(); for(int j=1;j<=n;j++) { if(mat[first.num][j]==true) { next.num=j; next.level=first.level+1; Q.push(next); } } } for(int i=1;i<=n;i++) { if(ans1<cnt[i]) {ans1=cnt[i]; ans2=i; } } } int main() { int id,k; while(scanf("%d%d",&n,&m)==2) { memset(mat,false,sizeof(mat)); memset(root,true,sizeof(root)); memset(cnt,0,sizeof(cnt)); int flag=0; for(int i=1;i<=m;i++) { scanf("%d%d",&id,&k); int id1; while(k--) { scanf("%d",&id1); mat[id][id1]=true; root[id1]=false; } for(int i=1;i<=n;i++) { if(root[i]==true) { for(int j=1;j<=n;j++) { if(mat[i][j]==true) { flag=1; R=i; break; } } } if(flag) break; } } ans1=-1; BFS(); printf("%d %d\n",ans1,ans2); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:水
原文地址:http://blog.csdn.net/xky1306102chenhong/article/details/46982741