2016/11/13周赛总结

来源:互联网 发布:安装软件 编辑:程序博客网 时间:2024/04/28 09:52

周赛链接: 点这里      密码:ACM7114

C - 简单的模拟

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice OpenJ_Bailian 2742

Description

判断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多 

Input

第1行是测试数据的组数n,每组测试数据占1行,是一个由a-z这26个字符组成的字符串 
每组测试数据之间有一个空行,每行数据不超过1000个字符且非空 

Output

n行,每行输出对应一个输入。一行输出包括出现次数最多的字符和该字符出现的次数,中间是一个空格。 
如果有多个字符出现的次数相同且最多,那么输出ascii码最小的那一个字符 

Sample Input

2abbcccadfadffasdf

Sample Output

c 3f 4
用了模拟思想,存代码

代码:

#include <stdio.h>#include <string.h>int main(){    int t;    scanf("%d",&t);    while(t--)    {        char a[1001];        scanf("%s",a);        int len=strlen(a);        int b[1000];        memset(b,0,sizeof(b));        for(int i=0;i<len;i++)        {            b[a[i]]++;        }        int max=0, j=0;        int i;        for(i=0;i<1000;i++)        {            if(b[i]!=0)            {                if(b[i]>max)                    max=b[i],j=i;            }        }        printf("%c %d\n",j,max);    }    return 0;}

D - 不那么难的模拟
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1020

Description

Given a string containing only 'A' - 'Z', we could encode it using the following method: 

1. Each sub-string containing k same characters should be encoded to " kX" where "X" is the only character in this sub-string. 

2. If the length of the sub-string is 1, '1' should be ignored.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.
 

Output

For each test case, output the encoded string in a line.
 

Sample Input

2ABCABBCCC

Sample Output

ABCA2B3C
本来应该和c题一样,但是那样顺序不对,遂换两一种思路,AC

代码:

#include <cstdio>#include <string.h>int main(){    int t;    char str[10001];    scanf("%d",&t);    while(t--)    {        scanf("%s",str);        int count=1;        for(int i=0; i<strlen(str); i++)        {            if(str[i]==str[i+1])                count++;            else            {                if(count==1)                    printf("%c",str[i]);                else                    printf("%d%c",count,str[i]);                count=1;            }        }        printf("\n");    }}

E - 有点难的模拟
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1088

Description

给出一段长度不超过十万的字符,按照规则输出即可。
遇到<br>另起一行输出,遇到<hr>,另起一行输出80个'-',一行最多输出80个字符, 输出一个完整单词时需要考虑加上这个单词,这一行的字符是否超过80,如果超过80,这个单词只能另起一行输出,每两个单词之间有一个空格。

Input

输入描述 如题

Output

输出描述 如题

Sample Input

Hallo, dies ist eine ziemlich lange Zeile, die in Htmlaber nicht umgebrochen wird.<br>Zwei <br> <br> produzieren zwei Newlines. Es gibt auch noch das tag <hr> was einen Trenner darstellt.Zwei <hr> <hr> produzieren zwei Horizontal Rulers.Achtung       mehrere Leerzeichen irritierenHtml genauso wenig wiemehrere Leerzeilen.

Sample Output

Hallo, dies ist eine ziemlich lange Zeile, die in Html aber nicht umgebrochenwird.Zweiproduzieren zwei Newlines. Es gibt auch noch das tag--------------------------------------------------------------------------------was einen Trenner darstellt. Zwei----------------------------------------------------------------------------------------------------------------------------------------------------------------produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Htmlgenauso wenig wie mehrere Leerzeilen.

Hint

沉迷翻译

日渐消瘦

//一道字符串处理的题

代码:

(方法一:)

//边存储边输出#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char s[200];int main(){    int sum=0;//记录字符串长度    while(~scanf("%s",s))//不停地输入,直到读完数据    {        if(strcmp(s,"<br>")==0)//遇见<br>换行        {            printf("\n");            sum=0;            continue;        }        if(strcmp(s,"<hr>")==0)//遇见<hr>加80个-        {            if(sum>0)            {                sum=0;                printf("\n");            }//清零sum             for(int i=0;i<80;i++)                printf("-");            printf("\n");            continue;        }        int len=strlen(s);        sum+=len;//记录已有的纯字符串长度        if(sum+1>80)        {            sum=len;            printf("\n%s",s);//把单词换下一行输出        }        else        {            if(sum>len)//一个单词和下一个单词要加空格                printf(" ");            printf("%s",s);            sum++;        }    }    printf("\n");//所有数据处理完换行    return 0;}
方法二(先存储,再输出):

//先存储完,后输出,比较美观,注释参考代码一#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char s[200];char a[10010];int main(){    int sum=0;    int num=0;    while(~scanf("%s",s))    {        if(strcmp(s,"<br>")==0)        {            a[num++]='\n';            sum=0;            continue;        }        if(strcmp(s,"<hr>")==0)        {            if(sum>0)            {                sum=0;                a[num++]='\n';            }            for(int i=0; i<80; i++)                a[num++]='-';            a[num++]='\n';            continue;        }        int len=strlen(s);        sum+=len;        if(sum+1>80)        {            sum=len;            a[num++]='\n';            for(int i=0; i<len; i++)                a[num++]=s[i];        }        else        {            if(sum>len)                a[num++]=' ';            for(int i=0; i<len; i++)                a[num++]=s[i];            sum++;        }    }    for(int i=0;i<num;i++)        printf("%c",a[i]);    printf("\n");    return 0;}


F - 复杂模拟
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
Submit Status Practice POJ 3087

Description

给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12。

将字符串s1和s2通过一定的变换变成s12,找到变换次数

变换规则如下:

假设s1=12345,s2=67890

变换后的序列 s=6172839405

如果s和s12完全相等那么输出变换次数

如果不完全相等,s的前半部分作为s1,后半部分作为s2,重复上述过程。

 

 

 

Input

第一行给出T(1≤T≤1000),代表有T组数据,每组数据首先给出len(1≤len≤100),接着给出两个长度为len的字符串s1 s2 然后给出长度为len*2的字符串s12。

 

 

 

Output

首先输出处理数据组的编号(编号从1开始)

再输出变换次数并换行。

注意两个数字之间有空格。

对于变换次数,如果无需变换直接得到s12,那么输出0,如果无论怎么变换都不会得到s12,那么输出 -1。

Sample Input

24AHAHHAHAHHAAAAHH3CDECDEEEDDCC

Sample Output

1 22 -1

Hint

模拟是代码能力的体现


代码:

//题解的代码:

#include<stdio.h>#include<string.h>char map_1[1005][105];//存储出现过的字符串char map_2[1005][105];int main(){    int T;    scanf("%d",&T);    for(int casen=1; casen<=T; casen++)    {        int len;        scanf("%d",&len);//单个字符串长度        char str_1[105];        char str_2[105];        char str_12[205];        char str[205];//目标字符串        scanf("%s%s%s",str_1,str_2,str_12);        strcpy(str,str_12);//目标字符串存到str        int steap=0;//需要多少步才能完成        while(1)        {            strcpy(map_1[steap],str_1);            strcpy(map_2[steap],str_2);//存储出现过的字符串            for(int i=0,j=0; i<len; i++)            {                str_12[j++]=str_2[i];                str_12[j++]=str_1[i];//获取拼接出来的字符串            }            steap++;//拼接操作次数加一            if(strcmp(str,str_12)==0)            {                printf("%d ",casen);                printf("%d\n",steap);                break;//拼接出来的字符串和目标字符串相等            }            for(int i=0; i<len; i++)                str_1[i]=str_12[i];//获取新的字符串1            for(int i=len,j=0; i<len*2; i++,j++)                str_2[j]=str_12[i];//获取新的字符串2            bool is_break=0;//需要时就置为1            for(int i=0; i<steap; i++)//检测新的字符串1是否出现过                if(strcmp(map_1[i],str_1)==0)                {                    printf("%d ",casen);                    printf("-1\n");                    is_break=1;                    break;                }            if(is_break==1)                break;            for(int i=0; i<steap; i++)//检测新的字符串2是否出现过                if(strcmp(map_2[i],str_2)==0)                {                    printf("%d ",casen);                    printf("-1\n");                    is_break=1;                    break;                }            if(is_break==1)                break;        }    }    return 0;}
我的代码:
//简化来写,用map来标识字符串有没有出现过,要学会map的使用
#include <stdio.h>#include <string.h>#include <string>#include <map>//用map来一一对应using namespace std;int main(){    int t;    scanf("%d",&t);    int q=0;//步骤标识    while(t--)    {        q++;        int len,i;        scanf("%d",&len);        char s1[201];        char s2[201];        char s12[401];        scanf("%s%s%s",s1,s2,s12);//读入数据        map<string,bool>v;//建立一个布尔型的map        v[s12]=true;        int step=0;//记录步数        while(1)        {            char s[201];            int j=0;            for(i=0; i<len; i++)//交叉读入字符串s            {                s[j++]=s2[i];                s[j++]=s1[i];            }            s[j]='\0';            step++;            if(strcmp(s,s12)==0)//用s和题目给出的字符串作比较            {                printf("%d %d\n",q,step);                break;            }            else if(v[s]==true&&strcmp(s,s12)!=0)//当v[s]为真且两个字符串不等时            {                printf("%d -1\n",q);                break;            }            v[s]=true;            for(i=0; i<len; i++)//如果不满足上面的条件就继续拆分            {                s1[i]=s[i];                s2[i]=s[i+len];            }            s1[i]='\0';            s2[i]='\0';//给后面加截止符        }    }    return 0;}


--------------------------

H - 计算几何初步
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice FZU 2110

Description

我会给你N 个点 的坐标,你来判断这 N个 点最多能 组成 多少个 完全不同 的锐角三角形。

Input

第一行给出T(T≤10),代表有T组数据。

每组数据首先给出N(1≤n≤100),接着有N行,每行给出两个整数x y(0≤|x|, |y|≤1,000,000) ,代表该点在平面直角坐标系中的坐标

Output

对于每组 数据 输出 结果并 换行

Sample Input

130 010 05 1000

Sample Output

1

Hint

锐角三角形任意两边平方和大于第三边平方


代码:

//就是要枚举每一种情况,用double类型

#include <stdio.h>#include <math.h>#include <string.h>struct zb//结构体存坐标{    double x;    double y;} q[105];int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        for(int i=0; i<n; i++)            scanf("%lf %lf",&q[i].x,&q[i].y);        double a,b,c;        int i,j,k,sum=0;        for(i=0; i<n-2; i++)//枚举三种情况            for(j=i+1; j<n-1; j++)                for(k=j+1; k<n; k++)//求三边平方                {                    a=(q[i].x-q[j].x)*(q[i].x-q[j].x)+(q[i].y-q[j].y)*(q[i].y-q[j].y);                    b=(q[i].x-q[k].x)*(q[i].x-q[k].x)+(q[i].y-q[k].y)*(q[i].y-q[k].y);                    c=(q[j].x-q[k].x)*(q[j].x-q[k].x)+(q[j].y-q[k].y)*(q[j].y-q[k].y);                    if(a+b>c&&a+c>b&&b+c>a)//任意两边平方和大于第三边                        sum++;                }        printf("%d\n",sum);    }    return 0;}


J - 再贪一心
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1257

Description

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. 

Input

输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔) 

Output

对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统. 

Sample Input

8 389 207 155 300 299 170 158 65

Sample Output

2
代码:

//参见NYOJ 又见拦截导弹#include<stdio.h>int main(){    int n,i,j,c,a[3000],q[3000];//q存导弹拦截系统    while(~scanf("%d",&n))    {        for(i=0; i<n; i++)            scanf("%d",&a[i]);//输入导弹数据        q[0]=a[0];//让拦截系统中第一个值等于第一个导弹飞来的高度        c=1;//拦截系统的个数        for(i=1; i<n; i++)        {            for(j=0; j<c; j++)//枚举当前导弹拦截系统的个数                if(a[i]<=q[j])//如果小于前一个证明可以拦截                {                    q[j]=a[i];//更新拦截系统的值                    break;                }            if(j>=c)//如果不能拦截            {                q[j]=a[i];//新的导弹系统的最大值                c++;            }        }        printf("%d\n",c);    }    return 0;}






0 1
原创粉丝点击