周赛总结(11.13)
来源:互联网 发布:网络医院预约挂号系统 编辑:程序博客网 时间:2024/06/05 10:29
1.Encoding
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.
2ABCABBCCC
ABCA2B3C
#include<stdio.h>#include<string.h>char a[10005];int main(){ int n; scanf("%d",&n); while(n--) { int i,la; scanf("%s",a); la=strlen(a); for(i=0; i<la;) { int k,s=1; for(k=i; k<=la; k++) { if(a[k]!=a[k+1]) break; s++; } if(s>1) printf("%d",s); printf("%c",a[k]); i+=s; } printf("\n"); } return 0;}
2.Write a simple HTML Browser
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.
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
#include<stdio.h>#include<string.h>int main(){ char s[100010][85]; int len,i=0,cnt=0,k,j; while(scanf("%s",s[i])!=EOF) i++; k=i; for(i=0; i<k; i++) { if(!strcmp(s[i],"<br>")) { printf("\n"); cnt=0; } else if(!strcmp(s[i],"<hr>")) { if(cnt) printf("\n"); for(j=0; j<80; j++) printf("-"); printf("\n"); cnt=0; } else { len=strlen(s[i]); if(!cnt) { printf("%s",s[i]); cnt=len; } else if(cnt+len+1>80) { printf("\n%s",s[i]); cnt=len; } else { printf(" %s",s[i]); cnt+=len+1; } } } printf("\n"); return 0;}
Description
A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several different colors.
The actual shuffle operation is performed by interleaving a chip from S1 with a chip from S2 as shown below for C = 5:
The single resultant stack, S12, contains 2 * C chips. The bottommost chip of S12 is the bottommost chip from S2. On top of that chip, is the bottommost chip from S1. The interleaving process continues taking the 2nd chip from the bottom of S2 and placing that on S12, followed by the 2nd chip from the bottom of S1 and so on until the topmost chip from S1 is placed on top of S12.
After the shuffle operation, S12 is split into 2 new stacks by taking the bottommost C chips from S12 to form a new S1 and the topmost C chips from S12 to form a new S2. The shuffle operation may then be repeated to form a new S12.
For this problem, you will write a program to determine if a particular resultant stack S12 can be formed by shuffling two stacks some number of times.
Input
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.
Each dataset consists of four lines of input. The first line of a dataset specifies an integer C, (1 ≤ C ≤ 100) which is the number of chips in each initial stack (S1 and S2). The second line of each dataset specifies the colors of each of the C chips in stack S1, starting with the bottommost chip. The third line of each dataset specifies the colors of each of the C chips in stack S2 starting with the bottommost chip. Colors are expressed as a single uppercase letter (A through H). There are no blanks or separators between the chip colors. The fourth line of each dataset contains 2 * Cuppercase letters (A through H), representing the colors of the desired result of the shuffling of S1 and S2 zero or more times. The bottommost chip’s color is specified first.
Output
Output for each dataset consists of a single line that displays the dataset number (1 though N), a space, and an integer value which is the minimum number of shuffle operations required to get the desired resultant stack. If the desired result can not be reached using the input for the dataset, display the value negative 1 (−1) for the number of shuffle operations.
Sample Input
24AHAHHAHAHHAAAAHH3CDECDEEEDDCC
Sample Output
1 22 -1
代码示例:
#include<stdio.h>#include<string.h>#include<iostream>#include<map>using namespace std;int main(){ int t,m=0; scanf("%d",&t); while(++m<=t) { int k,i; scanf("%d",&k); getchar(); char s1[201],s2[201],s12[401];//牌堆s1 牌堆s2 最终的牌堆状态s12 scanf("%s %s %s",s1,s2,s12); map<string,bool>vist;//记录出现过的洗牌状态(map缺省值为0) vist[s12]=true; int step=0;//洗牌次数 while(true) { char s[201];//当前s1与s2洗牌后的状态 int ps=0;//s[]指针 for(i=0;i<k;i++) { s[ps++]=s2[i];//s1与s2洗牌 s[ps++]=s1[i];//是从s2先开始的 } s[ps]='\0';//末尾结束 step++; if(!strcmp(s,s12))//当洗牌后的状态能达到预设状态时,输出 { printf("%d %d\n",m,step); break; } else if(vist[s])//当前洗牌后状态 与 前面出现过的状态重复了,但该状态不是预设状态 { printf("%d -1\n",m);//说明预设的状态无法达到 break; } vist[s]=true;//状态记录 for(i=0;i<k;i++)//分拆出s1与s2 { s1[i]=s[i]; s2[i]=s[i+k]; } s1[i]='\0'; s2[i]='\0'; } } return 0;}
ps:这题也是比较好的,学到了STL,但是map还是不太明白,还需多回顾,多锻炼。。
4.最少拦截系统
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
8 389 207 155 300 299 170 158 65
2
#include<stdio.h>int a[1000];int main(){ int n,t; while(~scanf("%d",&t)) { int tot,i,j; scanf("%d",&n); a[0]=n,tot=1; for(i=1;i<t;i++) { scanf("%d",&n); for(j=0;j<tot;j++) { if(n<=a[j]) { a[j]=n; break; } } if(j>=tot) a[tot++]=n; } printf("%d\n",tot); } return 0;}
#include<stdio.h>//**dp[i]表示第i个导弹飞过来时需要的最少拦截装置.**// int main() { int n,i,j,max,h[10001],dp[10001]; while(~scanf("%d",&n)) { max=-1; dp[0]=0; for(i=1;i<=n;i++) { scanf("%d",&h[i]);//**飞来的高度**// dp[i]=1;//**初始化拦截装置都为1**// } for(i=1;i<=n;i++) { for(j=i-1;j>=0;j--) { if(h[i]>h[j]&&dp[i]<dp[j]+1)//**如果在拦截中出现了非单调递减的**// { dp[i]=dp[j]+1; } } } for(i=1;i<=n;i++) { if(dp[i]>max) { max=dp[i]; } } printf("%d\n",max); } return 0; }
- 周赛总结(11.13)
- javase基础总结(周总结)
- day_7-acm 周赛总结(1)
- 周赛字符串总结
- 5.17周赛总结
- 周总结(一)
- 周总结(一)
- 集训两次周赛总结
- 周赛反思与总结
- 第一次周赛 3.15 总结
- 3.22第二次周赛总结
- 省赛总结(一)
- 省赛总结(二)
- 交流赛(赛后总结)
- 省赛总结(2015)
- 两周总结(一)
- 两周总结(二)
- 第三周总结(二)
- 早产的年终总结
- NOIP 2015 试做
- SVN
- HDU5685Problem A(逆元)
- codeforces475D——CGCDSSQ
- 周赛总结(11.13)
- 初始化整形数组 初始化双精度型数组
- LeetCode 282. Expression Add Operators
- java计算文件大小三种方法以及优缺点比较
- Java学习之二-Java反射机制
- IntelliJ IDEA中怎么查看文件中所有方法(类似eclipse里面的outline)
- MySql中时间类型无法设置默认0000-00-00的解决方法
- 通讯录程序(链表版)
- Python高效开发实战(web)——Django、Tornado、Flask、Twisted