PAT(A) 2015-03-14

A. To Buy or Not to Buy (20)

时间限制

100 ms

内存限制

65536 kB

代码长度限制

8000 B

判题程序

Standard

作者

CHEN, Yue

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.

Figure 1

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
YrR8RrY

Sample Output 1:

Yes 8

Sample Input 2:

ppRYYGrrYB225
YrR8RrY

Sample 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, Peng

The 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:

APPAPT

Sample 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, Yue

A 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 18

Sample 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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-08 23:24:06

PAT(A) 2015-03-14的相关文章

OpenSCAD 2015.03的大变化,更方便了。

OpenSCAD 2015.03出来了,有几个大的变化: 1.增加工具按钮,操作起来更方便,尤其是在Mac OS X的窗口全屏模式下. 2.坐标的标尺显示尺寸的刻度,这个对3D打印的模型设计很方便. 3.代码编辑器支持代码块折叠和自动缩进等专业代码编辑器的一些特征了. 注意:一定要自己下最新版的才有这个功能哦,我用mac port装的最新才14.03,没有这些个功能. 顺便唠叨下:到http://www.thingiverse.com,在搜索框输入openscad,可以找到大量的采用OpenSC

Hadoop自测题及参考答案(持续更新中--2015.6.14)

单选题 1.与其他几项不同的是 A. Mesos B. Mongodb C. Corona D. Borg E. YARN 注:其他几项都是资源统一管理系统或者资源统一调度系统,而 Mongodb一种非关系型数据库. 2.[java基础] 以下不属于线程安全的数据结构是 A. HashMap B. HashTable C. CopyOnWriteArrayList D. ConcurrentHashMap 3.hadoop2.x采用什么技术构建源代码 A. ant B. ivy C. maven

Murano Weekly Meeting 2015.07.14

2015.07.14 会议摘要 主持人:Kirill Zaitsev, core from Mirantis periodic nightly builds,然后通过mailing List发布出来,最终没有结论通过哪一个mailingList发布出来 1.yaql1.0 BP Action: kzaitsev从slagun处接手yaql1.0 BP with client and dashboard tasks. JS linting jobs (kzaitsev_mb, 17:32:05)

iOS 学习笔记 六 (2015.03.28)常见错误

2015.03.28 1. property's synthesized getter follows Cocoa naming convention for returning 'owned' objects You own any object you create You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, 

MyEclipse 2015 CI 14版来啦~带下载链接

经过两个月的努力,MyEclipse再次更新新版本2015 CI 14,此次更新又有很多新功能不容小视哦! 支持Web和Node.jsd的JavaScript Debugger调试器,新版本功能更加强大,在MyEclipse调试web应用程序变得更方便.调试器支持断点.变量和表达式. 类的动态预加载用Hot Reload功能在app 服务器上进行更改.这个功能可以帮助你节省很多时间,它既支持normal模式也支持debug模式,并且兼容Tomcat和Weblogic servers. REST

MyEclipse 2015 CI 14发布(附下载)

支持Web和Node.jsd的JavaScript Debugger调试器,新版本功能更加强大,在MyEclipse调试web应用程序变得更方便.调试器支持断点.变量和表达式. 类的动态预加载用Hot Reload功能在app 服务器上进行更改.这个功能可以帮助你节省很多时间,它既支持normal模式也支持debug模式,并且兼容Tomcat和Weblogic servers. REST Inspect提供可视化视图,这个功能让你发现.创建和测试端点.清爽的界面可以让你快速创建端点,并且在JQu

湖南多校对抗赛(2015.03.28) E Longest Increasing Subsequence Again

题意:给你一个序列,问你删除掉连续的一段,使得剩下的序列的最长上升字串最大,问你这个最大值. 解题思路:分段dp,  dp[i][0] ,dp[i][1]   , 0表示前面没有切过,只能从前一个数的0状态得到,1状态表示前面已经切过了,能从前一个的1状态得到,也能从 在他前面的比他值小的dp[j][0](j < i && a[j] < a[i])的最大值得到,这里用线段树维护就行了. 解题代码: 1 // File Name: b.cpp 2 // Author: darkd

湖南多校对抗赛(2015.03.28) G Good subsequence

题意:找到一个序列中极值<=k的最长字串的长度. 解题思路:set容器双递推. 解题代码: 1 // File Name: g.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月28日 星期六 12时04分39秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>

湖南多校对抗赛(2015.03.28) A Rectangle

题意:给你一些最多宽为2 的木板,让你放在一个宽为二的盒子里面,问你这个盒子最短有多长. 解题思路:DP,离中间最近的那个值. 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月28日 星期六 12时13分56秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9

湖南多校对抗赛(2015.03.28) B Design road

题意:给你起点(0,0),终点(x,y),中间有很多条河, 在河上面建桥花费c1,在陆地建路花费c2,问你最小花费是多少. 解题思路:我们知道,我们考虑的时候完全可以把河都移动到一边来求,这样只需要三分就行了. 解题代码: 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月28日 星期六 13时26分39秒 4 5 #include<vector> 6 #include<list> 7 #