摘要: 地址:http://codeforces.com/contest/266/problem/A可以看作是记录连续重复序列的长度和 1 #include<stdio.h> 2 3 int n; 4 char in[55]; 5 6 int main() 7 { 8 int i,count=0; 9 scanf("%d",&n);10 scanf("%s",in);11 for(i=0;i<n-1;i++)12 {13 if(in[i]==in[i+1])14 {15 count++;16 ... 阅读全文
posted @ 2013-01-23 15:17 tjsuhst 阅读(148) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1825第一次用C++写,因为是对二维数组排序,所以先在网上了解了一下,这里二维数组用int **来表示了对于sort的用法还要深入了解思路就是先按单价排序,然后将数量一个一个加起来比较 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,m; 6 int **f=new int*[5000]; 7 8 bool cmp(int *a,int *b) 9 {10 if(a[0]== 阅读全文
posted @ 2013-01-22 16:49 tjsuhst 阅读(248) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1824枚举,借用了“回文平方数”里的一些函数 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 int n,s; 6 7 int exam() 8 { 9 int p1=0,p2=(int)strlen(a)-1;10 while(p1<p2)11 {12 if(a[p1]!=a[p2]) {return 0;break;}13 p1++;14 p2--;15 ... 阅读全文
posted @ 2013-01-22 14:55 tjsuhst 阅读(256) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1823涉及到进制转换,要求输出在某进制下的回文数,用字符串处理会方便一些 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 6 void swap() 7 { 8 int l=(int)strlen(a); 9 int p1=0,p2=l-1;10 int t;11 while(p1<p2)12 {13 t=a[p1];14 a[p1++]=a[p2];15 ... 阅读全文
posted @ 2013-01-22 13:36 tjsuhst 阅读(409) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1820按开始时间排序,然后统计最长挤牛奶时间段和最长间隔段。快排又写错了一次...... 1 #include<stdio.h> 2 3 int a[5000][2],n; 4 5 int ones(int l,int r) 6 { 7 int i=l,j=r,flag=0,key=a[l][0]; 8 int t1,t2; 9 while(i<j)10 {11 if(0==flag)12 {13 if(a[j][... 阅读全文
posted @ 2013-01-22 12:26 tjsuhst 阅读(297) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/265/problem/B爬树吃坚果,很明显树顶走是最短路 1 #include<stdio.h> 2 3 int n,h[2]; 4 5 int main() 6 { 7 int i,ans=0; 8 scanf("%d",&n); 9 for(i=0;i<n;i++)10 {11 scanf("%d",&h[1]);12 if(0==i)13 {14 ans=h[1]+1;15 h[0]=h[1... 阅读全文
posted @ 2013-01-21 23:33 tjsuhst 阅读(306) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/233/problem/A这题好像做过,接下来几天要做点有难度的题 1 #include<stdio.h> 2 3 int n; 4 5 int main() 6 { 7 int i; 8 scanf("%d",&n); 9 if(n%2==0)10 {11 for(i=1;i<=n;i=i+2)12 printf("%d %d ",i+1,i);13 }14 else printf("-1\n");15 return 0;16 ... 阅读全文
posted @ 2013-01-21 22:50 tjsuhst 阅读(156) 评论(0) 推荐(1)
摘要: 地址:http://codeforces.com/contest/234/problem/A排座位,左右撇子都有,要求每两个人坐一起手不打架 1 #include<stdio.h> 2 3 int n; 4 5 int main() 6 { 7 int l,r; 8 char in[101]; 9 freopen("input.txt","r",stdin);10 freopen("output.txt","w",stdout);11 scanf("%d",&n);12 sc 阅读全文
posted @ 2013-01-21 22:41 tjsuhst 阅读(242) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/239/problem/A按题目说的求就是了 1 #include<stdio.h> 2 3 int y,k,n; 4 5 int main() 6 { 7 int i; 8 scanf("%d %d %d",&y,&k,&n); 9 i=(y/k+1)*k-y;10 if(i>n-y) printf("-1\n");11 else12 {13 while(i<=n-y)14 {15 printf("%d ",i);16 阅读全文
posted @ 2013-01-21 18:01 tjsuhst 阅读(169) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/265/problem/A昨晚没时间参赛 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[50],b[50]; 5 6 int main() 7 { 8 int i=0,j=0,len; 9 scanf("%s",a);10 scanf("%s",b);11 len=(int)strlen(b);12 for(j=0;j<len;j++)13 {14 if(b[j]==a[i]) i++;15 }1... 阅读全文
posted @ 2013-01-21 11:56 tjsuhst 阅读(163) 评论(0) 推荐(0)