2016/11/13周赛总结
来源:互联网 发布:安装软件 编辑:程序博客网 时间:2024/04/28 09:52
周赛链接: 点这里 密码:ACM7114
C - 简单的模拟
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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;}
Description
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
代码:
#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"); }}
Description
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;}
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;}
#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;}
--------------------------
Description
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;}
Description
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
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;}
- 2016/11/13周赛总结
- 2016年11月13日周工作知识点总结
- 2016/11/27月赛总结
- 2016山东省赛总结
- 周赛字符串总结
- 5.17周赛总结
- 第13周总结
- 13周总结
- 第11周总结
- 1508-张晨曦总结《2016年-11月-3日》【连续13天总结】
- 1508-张晨曦总结《2016年-11月-13日》【连续23天总结】
- 1613-3-傅溥衍 总结《2016年11月13日》【连续四十四天总结】
- #总结 2015.12.13总结
- 2016ACM省赛总结
- 2016四川省省赛总结
- 2016-7-13考试总结
- 洛谷11月月赛总结
- NOIP2017模拟赛(11) 总结
- 菜鸟学学ReactNative笔记(二)
- opencv里平均背景法
- 4086.韩信点兵
- 1小时学会:最简单的iOS直播推流(三)使用系统接口捕获音视频数据
- iOS中将,NSArray转换成json数据
- 2016/11/13周赛总结
- SVG中的动画
- Android listview下拉刷新,出现重复数据
- 华为m2 803l 电信设置上网,亲测
- Linux系统中常见目录的作用
- PHP环境搭建
- oracle如何判断number类型为空
- 我的服务器开发之路-配置apache
- Git pull 后恢复到原来版本