﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-烟雨江南-随笔分类-USACO 题解</title><link>http://www.cppblog.com/laysent/category/12202.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 15 Nov 2009 18:23:42 GMT</lastBuildDate><pubDate>Sun, 15 Nov 2009 18:23:42 GMT</pubDate><ttl>60</ttl><item><title>USACO-The Clocks</title><link>http://www.cppblog.com/laysent/archive/2009/11/15/100964.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sun, 15 Nov 2009 03:49:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/15/100964.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100964.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/15/100964.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100964.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100964.html</trackback:ping><description><![CDATA[一开始想用DFS解决，结果发现实在想不出什么好一点的启发函数可以让搜索较快得到优先解。然后就改用ID，但是时间拖得太长了，只过了两个数据就卡住了。最后想来想去想不好，干脆用穷举法，反正才4^9种可能。终于过了。<br><br>#include"stdio.h"<br>FILE *fin,*fout;<br>int answer[33],a[9],maxcount,mincount=28,sum[10];<br><br>int change(int a)<br>{<br>&nbsp;&nbsp;&nbsp; if (a&lt;12)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (a+3);<br>&nbsp;&nbsp;&nbsp; if (a==12)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (3);<br>}<br><br>search(s1,s2,s3,s4,s5,s6,s7,s8,s9)<br>int s1,s2,s3,s4,s5,s6,s7,s8,s9;<br>{<br>&nbsp;&nbsp;&nbsp; int k,j,count=0,check=0,s[10],aa,b,c,d,e,f,h,g,i;<br>&nbsp;&nbsp;&nbsp; s[1]=s1;s[2]=s2;s[3]=s3;s[4]=s4;s[5]=s5;s[6]=s6;s[7]=s7;s[8]=s8;s[9]=s9;<br>&nbsp;&nbsp;&nbsp; aa=a[0];b=a[1];c=a[2];d=a[3];e=a[4];f=a[5];g=a[6];h=a[7];i=a[8];<br>&nbsp;&nbsp;&nbsp; for (k=1;k&lt;=9;k++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (j=1;j&lt;=s[k];j++)/*改变clocks的数值*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==1) {aa=change(aa);b=change(b);d=change(d);e=change(e);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==2) {aa=change(aa);b=change(b);c=change(c);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==3) {b=change(b);c=change(c);e=change(e);f=change(f);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==4) {aa=change(aa);d=change(d);g=change(g);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==5) {b=change(b);d=change(d);e=change(e);f=change(f);h=change(h);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==6) {c=change(c);f=change(f);i=change(i);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==7) {d=change(d);e=change(e);g=change(g);h=change(h);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==8) {g=change(g);h=change(h);i=change(i);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (k==9) {e=change(e);f=change(f);h=change(h);i=change(i);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; check=0;<br>&nbsp;&nbsp;&nbsp; if (aa==12 &amp;&amp; b==12 &amp;&amp; c==12 &amp;&amp; d==12 &amp;&amp; e==12 &amp;&amp; f==12 &amp;&amp; g==12 &amp;&amp; h==12 &amp;&amp; i==12)/*验证是否满足*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; check=1;<br>&nbsp;&nbsp;&nbsp; count=0;<br>&nbsp;&nbsp;&nbsp; if (check==1) /*满足则记录答案*/<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (k=1;k&lt;=9;k++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (j=1;j&lt;=s[k];j++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[count]=k;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mincount=count-1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>}<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int i,j,tem,s1,s2,s3,s4,s5,s6,s7,s8,s9;<br>&nbsp;&nbsp;&nbsp; fin=fopen("clocks.in","r");<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;7;i+=3)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fscanf(fin,"%d %d %d\n",&amp;a[i],&amp;a[i+1],&amp;a[i+2]);<br>&nbsp;&nbsp;&nbsp; fclose(fin);<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=10;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sum[i]=0;<br>&nbsp;&nbsp;&nbsp; for (s9=0;s9&lt;=3;s9++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s8=0;s8&lt;=3;s8++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s7=0;s7&lt;=3;s7++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s6=0;s6&lt;=3;s6++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s5=0;s5&lt;=3;s5++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s4=0;s4&lt;=3;s4++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s3=0;s3&lt;=3;s3++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s2=0;s2&lt;=3;s2++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (s1=0;s1&lt;=3;s1++) /*遍历所有可能的情况*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (s1+s2+s3+s4+s5+s6+s7+s8+s9&lt;mincount) /*减去一些必然不是最优解的情况*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; search(s1,s2,s3,s4,s5,s6,s7,s8,s9);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=mincount;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (j=i+1;j&lt;=mincount;j++) /*将答案自小到大排列*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (answer[i]&gt;answer[j])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tem=answer[i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[i]=answer[j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[j]=tem;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; fout=fopen("clocks.out","w");<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d",answer[0]);<br>&nbsp;&nbsp;&nbsp; for (i=1;i&lt;=mincount;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fout," %d",answer[i]);<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"\n");<br>&nbsp;&nbsp;&nbsp; fclose(fout);<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br><br><img src ="http://www.cppblog.com/laysent/aggbug/100964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-15 11:49 <a href="http://www.cppblog.com/laysent/archive/2009/11/15/100964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Packing Rectangles</title><link>http://www.cppblog.com/laysent/archive/2009/11/14/100927.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 14 Nov 2009 09:29:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/14/100927.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100927.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/14/100927.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100927.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100927.html</trackback:ping><description><![CDATA[不太简单的一道题目。如果USACO没有给出提示的话我想我是做不出来的。<br>一共有六种情况，其中有两种是相似的，可以归并为一种。有了提示，方法也就容易想到了。就是列举所有的可能性，然后放到五种情况里面去计算面积大小。只不过写起来就比较麻烦了。<br><br>#include "stdio.h"<br>#define MAX 10000 /*MAX记录面积最大上限，用于初始化*/<br>FILE *fin,*fout;<br>int maxs=MAX,a[3][10], answer[3][10],count=0;/*maxs记录最大面积，a存储矩形边长，count用于计算答案个数*/<br><br>int change(int i) <br>{<br>&nbsp;&nbsp;&nbsp; if (i==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(2);<br>&nbsp;&nbsp;&nbsp; if(i==2)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br>}<br><br>int max(a,b,c,d)/*找最大值*/<br>int a,b,c,d;<br>{<br>&nbsp;&nbsp;&nbsp; int maxn;<br>&nbsp;&nbsp;&nbsp; maxn=a;<br>&nbsp;&nbsp;&nbsp; if (maxn&lt;b)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; maxn=b;<br>&nbsp;&nbsp;&nbsp; if (maxn&lt;c)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; maxn=c;<br>&nbsp;&nbsp;&nbsp; if (maxn&lt;d)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; maxn=d;<br>&nbsp;&nbsp;&nbsp; return maxn;<br>}<br><br>void culculate(length,width) /*计算面积并记录*/<br>int length,width;<br>{<br>&nbsp;&nbsp;&nbsp; int i,check=0;<br>&nbsp;&nbsp;&nbsp; if (maxs==length*width)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; check=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&lt;count;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (answer[1][i]==(length&gt;width?length:width))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; check=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (check==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {answer[1][count]=(length&gt;width?length:width);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[2][count]=(length&lt;width?length:width);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;}<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (maxs&gt;length*width)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; maxs=length*width;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[1][count]=(length&gt;width?length:width);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[2][count]=(length&lt;width?length:width);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>void simulate(s1,d1,s2,d2,s3,d3,s4,d4) /*模拟所有的可能性*/<br>int s1,d1,s2,d2,s3,d3,s4,d4;<br>{<br>&nbsp;&nbsp;&nbsp; int k1,k2,k3,k4,length,width;<br>&nbsp;&nbsp;&nbsp; k1=change(d1);k2=change(d2);k3=change(d3);k4=change(d4);<br>&nbsp;&nbsp;&nbsp; /*模拟第一种情况*/<br>&nbsp;&nbsp;&nbsp; length=a[d1][s1]+a[d2][s2]+a[d3][s3]+a[d4][s4];<br>&nbsp;&nbsp;&nbsp; width=max(a[k1][s1],a[k2][s2],a[k3][s3],a[k4][s4]);<br>&nbsp;&nbsp;&nbsp; culculate(length,width);<br>&nbsp;&nbsp;&nbsp; /*模拟第二种情况*/<br>&nbsp;&nbsp;&nbsp; length=max(a[d1][s1]+a[d2][s2]+a[d3][s3],a[d4][s4],0,0);<br>&nbsp;&nbsp;&nbsp; width=max(a[k1][s1],a[k2][s2],a[k3][s3],0)+a[k4][s4];<br>&nbsp;&nbsp;&nbsp; culculate(length,width);<br>&nbsp;&nbsp;&nbsp; /*模拟第三种情况*/<br>&nbsp;&nbsp;&nbsp; length=max(a[d1][s1]+a[d2][s2],a[d3][s3],0,0)+a[d4][s4];<br>&nbsp;&nbsp;&nbsp; width=max(a[k1][s1]+a[k3][s3],a[k3][s3]+a[k2][s2],a[k4][s4],0);<br>&nbsp;&nbsp;&nbsp; culculate(length,width);<br>&nbsp;&nbsp;&nbsp; /*模拟第四种情况*/<br>&nbsp;&nbsp;&nbsp; length=a[d1][s1]+a[d2][s2]+max(a[d3][s3],a[d4][s4],0,0);<br>&nbsp;&nbsp;&nbsp; width=max(a[k1][s1],a[k2][s2],a[k3][s3]+a[k4][s4],0);<br>&nbsp;&nbsp;&nbsp; culculate(length,width);<br>&nbsp;&nbsp;&nbsp; /*模拟第五种情况*/<br>&nbsp;&nbsp;&nbsp; if (a[k3][s3]&gt;a[k2][s2]+a[k4][s4])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=max(a[d1][s1],a[d2][s2]+a[d3][s3],a[d3][s3]+a[d4][s4],0);<br>&nbsp;&nbsp;&nbsp; if (a[k3][s3]&gt;a[k4][s4] &amp;&amp; a[k3][s3]&lt;a[k2][s2]+a[k4][s4])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=max(a[d1][s1]+a[d2][s2],a[d2][s2]+a[d3][s3],a[d3][s3]+a[d4][s4],0);<br>&nbsp;&nbsp;&nbsp; if (a[k4][s4]&gt;a[k3][s3] &amp;&amp; a[k4][s4]&lt;a[k1][s1]+a[k3][s3])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=max(a[d1][s1]+a[d2][s2],a[d1][s1]+a[d4][s4],a[d3][s3]+a[d4][s4],0);<br>&nbsp;&nbsp;&nbsp; if (a[k4][s4]&gt;=a[k1][s1]+a[k3][s3])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=max(a[d2][s2],a[d1][s1]+a[d4][s4],a[d3][s3]+a[d4][s4],0);<br>&nbsp;&nbsp;&nbsp; if (a[k3][s3]==a[k4][s4])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=max(a[d1][s1]+a[d2][s2],a[d3][s3]+a[d4][s4],0,0);<br>&nbsp;&nbsp;&nbsp; width=max(a[k1][s1]+a[k3][s3],a[k2][s2]+a[k4][s4],0,0);<br>&nbsp;&nbsp;&nbsp; culculate(length,width);<br>}<br><br>sort()<br>{<br>&nbsp;&nbsp;&nbsp; int tem,i,j;<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;count;i++) /*冒泡算法。虽然时间复杂度比较大，但是数据量小，所以还是比较适用的*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (j=i+1;j&lt;count;j++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (answer[2][i]&gt;answer[2][j])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tem=answer[1][i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[1][i]=answer[1][j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[1][j]=tem;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tem=answer[2][i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[2][i]=answer[2][j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; answer[2][j]=tem;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; fout=fopen("packrec.out","w");<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d\n",maxs);<br>&nbsp;&nbsp;&nbsp; tem=0;<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;count;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (answer[2][i]!=tem)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fout,"%d %d\n",answer[2][i],answer[1][i]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tem=answer[2][i];<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; fclose(fout);<br>}<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int i,s1,s2,s3,s4,d1,d2,d3,d4;<br>&nbsp;&nbsp;&nbsp; fin=fopen("packrec.in","r");<br>&nbsp;&nbsp;&nbsp; for (i=1;i&lt;5;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fscanf(fin,"%d %d\n",&amp;a[1][i],&amp;a[2][i]);<br>&nbsp;&nbsp;&nbsp; fclose(fin); /*读入数据*/<br>&nbsp;&nbsp;&nbsp; for (s1=1;s1&lt;5;s1++) /*排列组合所有可能的情况*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (s2=1;s2&lt;5;s2++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (s1!=s2)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for(s3=1;s3&lt;5;s3++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (s3!=s2 &amp;&amp; s3!=s1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (s4=1;s4&lt;5;s4++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (s4!=s1 &amp;&amp; s4!=s2&amp;&amp; s4!=s3)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (d1=1;d1&lt;3;d1++)/*以下变量的变化决定了矩形是横的还是竖的*/<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (d2=1;d2&lt;3;d2++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (d3=1;d3&lt;3;d3++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {for (d4=1;d4&lt;3;d4++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; simulate(s1,d1,s2,d2,s3,d3,s4,d4);}}}}}}}}}}<br>&nbsp;&nbsp;&nbsp; sort();<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/100927.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-14 17:29 <a href="http://www.cppblog.com/laysent/archive/2009/11/14/100927.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Barn Repair</title><link>http://www.cppblog.com/laysent/archive/2009/11/09/100476.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Mon, 09 Nov 2009 07:45:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/09/100476.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100476.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/09/100476.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100476.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100476.html</trackback:ping><description><![CDATA[<p>#include "stdio.h"<br>#define MAX 200<br>FILE *fin,*fout;</p>
<p>void sort(temp,start,end)<br>int temp[],start,end;<br>{<br>&nbsp;int i,j,tem;<br>&nbsp;for (i=start;i&lt;=end;i++)<br>&nbsp;{<br>&nbsp;&nbsp;for (j=i+1;j&lt;=end;j++)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;if (temp[i]&gt;temp[j])<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;tem=temp[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;temp[i]=temp[j];<br>&nbsp;&nbsp;&nbsp;&nbsp;temp[j]=tem;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}</p>
<p>main()<br>{<br>&nbsp;int i,stall,maxn,cown,cow[202],crack[203],start,count,lenth=0,need=0;<br>&nbsp;fin=fopen("barn1.in","r");<br>&nbsp;fscanf(fin,"%d %d %d\n",&amp;stall,&amp;maxn,&amp;cown);<br>&nbsp;for (i=0;i&lt;cown;i++)<br>&nbsp;&nbsp;fscanf(fin,"%d\n",&amp;cow[i]);<br>&nbsp;fclose(fin);<br>&nbsp;sort(cow,0,cown-1);<br>&nbsp;fout=fopen("barn1.out","w");<br>&nbsp;start=cow[0];<br>&nbsp;count=0;<br>&nbsp;for (i=1;i&lt;cown;i++)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;if (cow[i]-cow[i-1]!=1)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;crack[count]=cow[i]-cow[i-1]-1;<br>&nbsp;&nbsp;&nbsp;&nbsp;start=cow[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;count++;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br>&nbsp;lenth=cown;<br>&nbsp;need=count-stall+1;<br>&nbsp;sort(crack,0,count-1);<br>&nbsp;for (i=0;i&lt;need;i++)<br>&nbsp;&nbsp;lenth+=crack[i];<br>&nbsp;fprintf(fout,"%d\n",lenth);<br>&nbsp;fclose(fout);<br>&nbsp;return 0;<br>}</p>
<img src ="http://www.cppblog.com/laysent/aggbug/100476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-09 15:45 <a href="http://www.cppblog.com/laysent/archive/2009/11/09/100476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Mixing Milk</title><link>http://www.cppblog.com/laysent/archive/2009/11/07/100337.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 07 Nov 2009 05:33:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/07/100337.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100337.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/07/100337.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100337.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100337.html</trackback:ping><description><![CDATA[<p>#include "stdio.h"<br>#define MAX 5000/* the number of farmers at most*/<br>FILE *fin,*fout;<br>int cent[MAX];long amount[MAX];</p>
<p>void quicksort(int start,int end)<br>{<br>int i,j,temp;<br>long longtemp;<br>i=start;j=end;<br>while (i&lt;j)<br>{<br>&nbsp;while (cent[i]&lt;=cent[j] &amp;&amp; i&lt;j)<br>&nbsp;&nbsp;i++;<br>&nbsp;if (cent[i]&gt;cent[j])<br>&nbsp;{temp=cent[j];<br>&nbsp;cent[j]=cent[i];<br>&nbsp;cent[i]=temp;<br>&nbsp;longtemp=amount[j];<br>&nbsp;amount[j]=amount[i];<br>&nbsp;amount[i]=longtemp;}<br>&nbsp;while (cent[j]&gt;=cent[i] &amp;&amp; i&lt;j)<br>&nbsp;&nbsp;j--;<br>&nbsp;if (cent[j]&lt;cent[i])<br>&nbsp;{temp=cent[j];<br>&nbsp;cent[j]=cent[i];<br>&nbsp;cent[i]=temp;<br>&nbsp;longtemp=amount[j];<br>&nbsp;amount[j]=amount[i];<br>&nbsp;amount[i]=longtemp;}<br>}<br>if (start&lt;j) quicksort(start,j-1);<br>if (i&lt;end) quicksort(i+1,end);<br>}</p>
<p>main()<br>{<br>int num,i;<br>long aim,money=0,have=0;<br>fin=fopen("milk.in","r");<br>fscanf(fin,"%ld %d\n",&amp;aim,&amp;num);<br>for (i=0;i&lt;num;i++)<br>&nbsp;fscanf(fin,"%d %ld\n",&amp;cent[i],&amp;amount[i]);<br>fclose(fin);<br>quicksort(0,num-1);<br>for (i=0;i&lt;num;i++)<br>{<br>&nbsp;if (have&gt;=aim)<br>&nbsp;&nbsp;break;<br>&nbsp;else<br>&nbsp;{<br>&nbsp;&nbsp;if (have+amount[i]&lt;=aim)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;have+=amount[i];<br>&nbsp;&nbsp;&nbsp;money+=cent[i]*amount[i];<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;money+=cent[i]*(aim-have);<br>&nbsp;&nbsp;&nbsp;have=aim;<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}<br>fout=fopen("milk.out","w");<br>fprintf(fout,"%ld\n",money);<br>fclose(fout);<br>return (0);<br>}</p>
<img src ="http://www.cppblog.com/laysent/aggbug/100337.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-07 13:33 <a href="http://www.cppblog.com/laysent/archive/2009/11/07/100337.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Dual Palindromes</title><link>http://www.cppblog.com/laysent/archive/2009/11/04/100106.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Wed, 04 Nov 2009 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/04/100106.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100106.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/04/100106.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100106.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100106.html</trackback:ping><description><![CDATA[#include "stdio.h"<br>FILE *fin,*fout;<br>int counter;<br><br>palindrom(int zahl)<br>{int count=0,check=0,basis,quadrat,i,j,k;<br>char number[20];<br>for (basis=2;basis&lt;=10;basis++)<br>{<br>quadrat=zahl;<br>for (i=0;i&lt;=count;i++)<br>&nbsp;&nbsp;&nbsp; number[i]='0';<br>number[0]=quadrat % basis +48;<br>count=1;<br>quadrat=quadrat/basis;<br>while (quadrat&gt;=basis)<br>{<br>number[count]=quadrat % basis +48;<br>count++;quadrat=quadrat/basis;<br>}<br>if (quadrat!=0) {number[count]=quadrat+48;count++;}<br>k=1;<br>for(i=0,j=count-1;i&lt;=j;i++,j--)<br>&nbsp;&nbsp;&nbsp; if (number[i]!=number[j])<br>&nbsp;&nbsp;&nbsp; {k=0;break;}<br>if (k==1)<br>check++;<br>if (check&gt;=2)<br>{<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d\n",zahl);<br>&nbsp;&nbsp;&nbsp; counter++;<br>&nbsp;&nbsp;&nbsp; break;<br>}<br>}<br>}<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int num,startnum,pronum;<br>&nbsp;&nbsp;&nbsp; fin=fopen("dualpal.in","r");<br>&nbsp;&nbsp;&nbsp; fout=fopen("dualpal.out","w");<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%d %d\n",&amp;num,&amp;startnum);<br>&nbsp;&nbsp;&nbsp; fclose(fin);<br>&nbsp;&nbsp;&nbsp; counter=0;<br>&nbsp;&nbsp;&nbsp; while (counter&lt;num)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; startnum++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pronum=startnum;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; palindrom(pronum);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/100106.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-04 11:31 <a href="http://www.cppblog.com/laysent/archive/2009/11/04/100106.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Palindromic Squares</title><link>http://www.cppblog.com/laysent/archive/2009/11/04/100100.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Wed, 04 Nov 2009 03:04:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/04/100100.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/100100.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/04/100100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/100100.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/100100.html</trackback:ping><description><![CDATA[这个程序自以为写得极差。因为一开始题目没看清楚的缘故，结果平白无故又只能多加几个函数上去。整个程序很冗长。真是败笔啊。<br><br>#include "stdio.h"<br>#define MAX 300<br>char number1[17],number2[17];<br>int base;<br>FILE *fin,*fout;<br><br>void transform(int stop)<br>{<br>&nbsp;&nbsp;&nbsp; int i,j;<br>&nbsp;&nbsp;&nbsp; char tem;<br>&nbsp;&nbsp;&nbsp; for (i=0,j=stop-1;i&lt;=j;i++,j--)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tem=number1[i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; number1[i]=number1[j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; number1[j]=tem;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>}<br><br>trans (quadrat,basis)<br>int quadrat,basis;<br>{int count;<br>if((quadrat %basis)&gt; 9)<br>number1[0]=quadrat % basis+55;<br>else number1[0]=quadrat % basis +48;<br>count=1;<br>quadrat=quadrat/basis;<br>while (quadrat&gt;=basis)<br>{ if((quadrat %basis)&gt; 9)<br>number1[count]=quadrat % basis+55;<br>else number1[count]=quadrat % basis +48;<br>count++;quadrat=quadrat/basis;<br>}<br>if (quadrat&gt;9)<br>&nbsp;number1[count]=quadrat+55;<br>else if (quadrat!=0) {number1[count]=quadrat+48;count++;<br>&nbsp;&nbsp;&nbsp; transform(count);}<br>}<br><br>int transbase (quadrat,basis)<br>int quadrat,basis;<br>{int count;<br>if((quadrat %basis)&gt; 9)<br>number2[0]=quadrat % basis+55;<br>else number2[0]=quadrat % basis +48;<br>count=1;<br>quadrat=quadrat/basis;<br>while (quadrat&gt;=basis)<br>{ if((quadrat %basis)&gt; 9)<br>number2[count]=quadrat % basis+55;<br>else number2[count]=quadrat % basis +48;<br>count++;quadrat=quadrat/basis;<br>}<br>if (quadrat&gt;9)<br>&nbsp;{number2[count]=quadrat+55;count++;}<br>else if (quadrat!=0) {number2[count]=quadrat+48;count++;}<br>return(count);}<br><br>check(counter,ii)<br>int counter,ii;<br>{int i,j,k;<br>k=1;<br>for(i=0,j=counter-1;i&lt;=j;i++,j--)<br>&nbsp;&nbsp;&nbsp; if (number2[i]!=number2[j])<br>&nbsp;&nbsp;&nbsp; k=0;<br>if (k==1)<br>{ trans(ii,base);<br>fprintf(fout,"%s %s\n",number1,number2);}}<br><br>main()<br>{<br>int i,trans,square;<br>fin=fopen("palsquare.in","r");<br>fout=fopen("palsquare.out","w");<br>fscanf(fin,"%d\n",&amp;base);<br>for (i=1;i&lt;=MAX;i++)<br>{square=i*i;<br>trans=transbase(square,base);<br>check(trans,i);}<br>return(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/100100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-04 11:04 <a href="http://www.cppblog.com/laysent/archive/2009/11/04/100100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Name That Number</title><link>http://www.cppblog.com/laysent/archive/2009/11/01/99950.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sun, 01 Nov 2009 14:01:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/11/01/99950.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99950.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/11/01/99950.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99950.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99950.html</trackback:ping><description><![CDATA[#include "stdio.h"<br>FILE *fin,*fout,*fdict;<br>char number[15],print[15];<br>static int checkstop[8]={67,70,73,76,79,83,86,89},checkbegin[8]={65,68,71,74,77,80,74,87};<br><br>int check(int counter)<br>{<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='2' &amp;&amp; (print[counter]=='A' || print[counter]=='B'||print[counter]=='C')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='3' &amp;&amp; (print[counter]=='D' || print[counter]=='E'||print[counter]=='F')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='4' &amp;&amp; (print[counter]=='G' || print[counter]=='H'||print[counter]=='I')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='5' &amp;&amp; (print[counter]=='J' || print[counter]=='K'||print[counter]=='L')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='6' &amp;&amp; (print[counter]=='M' || print[counter]=='N'||print[counter]=='O')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='7' &amp;&amp; (print[counter]=='P' || print[counter]=='R'||print[counter]=='S')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='8' &amp;&amp; (print[counter]=='T' || print[counter]=='U'||print[counter]=='V')) return 1;<br>&nbsp;&nbsp;&nbsp; if (number[counter]=='9' &amp;&amp; (print[counter]=='W' || print[counter]=='X'||print[counter]=='Y')) return 1;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int num,count,printcheck,printcount=0,i,begin,stop;<br>&nbsp;&nbsp;&nbsp; fin=fopen("namenum.in","r");<br>&nbsp;&nbsp;&nbsp; fdict=fopen("dict.txt","r");<br>&nbsp;&nbsp;&nbsp; fout=fopen("namenum.out","w");<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%s\n",number);<br>&nbsp;&nbsp;&nbsp; num=strlen(number);<br>&nbsp;&nbsp;&nbsp; fclose(fin);<br>&nbsp;&nbsp;&nbsp; begin=checkbegin[number[0]-50];<br>&nbsp;&nbsp;&nbsp; stop=checkstop[number[0]-50];<br>&nbsp;&nbsp;&nbsp; fscanf(fdict,"%s\n",print);<br>&nbsp;&nbsp;&nbsp; while (stop&gt;=print[0])<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (begin&lt;=print[0] &amp;&amp; stop &gt;=print[0])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (num==strlen(print))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printcheck=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&lt;=num-1;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (check(i)==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printcheck=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (printcheck==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fout,"%s\n",print);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printcount++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fscanf(fdict,"%s\n",print);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; fscanf(fdict,"%s\n",print);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (printcount==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fout,"NONE\n");<br>&nbsp;&nbsp;&nbsp; fclose(fout);<br>&nbsp;&nbsp;&nbsp; fclose(fdict);<br>&nbsp;&nbsp;&nbsp; return(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99950.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-11-01 22:01 <a href="http://www.cppblog.com/laysent/archive/2009/11/01/99950.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Greedy Gift Givers</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99885.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:16:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99885.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99885.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99885.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99885.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99885.html</trackback:ping><description><![CDATA[#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;<br>int main()<br>{<br>int i,j,ng,np,present,togive,gp,rp;<br>char names[10][15],tname[15];<br>int given[10],received[10];<br>&nbsp;&nbsp;&nbsp; FILE *fin=fopen("gift1.in","r");<br>&nbsp;&nbsp;&nbsp; FILE *fout=fopen("gift1.out","w");<br>fscanf(fin,"%d\n",&amp;np);<br>for(i=0;i&lt;np;i++)<br>{<br>&nbsp;&nbsp; fscanf(fin,"%s\n",names[i]);<br>&nbsp;&nbsp; given[i]=received[i]=0;<br>}<br>for(i=0;i&lt;np;i++)<br>{<br>&nbsp;&nbsp; fscanf(fin,"%s\n%d %d",tname,&amp;present,&amp;ng);<br>&nbsp;&nbsp; for(gp=0;gp&lt;np;gp++)<br>&nbsp;if(ng&amp;&amp;strcmp(names[gp],tname)==0) { given[gp]+=present-present%ng; togive=present/ng; break;}<br>&nbsp;&nbsp; for(j=0;j&lt;ng;j++)<br>&nbsp;&nbsp; {<br>&nbsp; fscanf(fin,"%s\n",tname);<br>&nbsp; for(rp=0;rp&lt;np;rp++)<br>&nbsp; if(strcmp(names[rp],tname)==0)<br>&nbsp; {<br>&nbsp; received[rp]+=togive;<br>&nbsp; break;<br>&nbsp; }<br>&nbsp;&nbsp; }<br>}<br>for(i=0;i&lt;np;i++)<br>&nbsp; fprintf(fout,"%s %d\n",names[i],received[i]-given[i]);<br>return 0;<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99885.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:16 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99885.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Transformations</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99884.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:15:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99884.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99884.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99884.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99884.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99884.html</trackback:ping><description><![CDATA[#include "stdio.h"<br>#include "math.h"<br>FILE *fin,*fout;<br>int outputn=7,num,combinate=0;<br>long picture[9]={0},reflect[9]={0};<br><br>scan()<br>{<br>char propic[10];int i,k;<br>for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; {fscanf(fin,"%s\n",propic);<br>&nbsp;&nbsp;&nbsp; &nbsp;for (k=0;k&lt;=(num-1);k++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (propic[k]=='@')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{picture[i]&lt;&lt;=1;picture[i]=picture[i]+1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (propic[k]=='-')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; picture[i]&lt;&lt;=1;}}<br>for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; {fscanf(fin,"%s\n",propic);<br>&nbsp;&nbsp;&nbsp; &nbsp;for (k=0;k&lt;=(num-1);k++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (propic[k]=='@')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{reflect[i]&lt;&lt;=1;reflect[i]=reflect[i]+1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (propic[k]=='-')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; reflect[i]&lt;&lt;=1;}}<br>fclose(fin);<br>}<br><br>reflection()<br>{int i,j,count=0,correct=1;long propic,proref;<br>&nbsp;&nbsp;&nbsp; while(count&lt;=num-1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; for (i=num-1,j=0;i&gt;=0;i--,j++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=picture[count]&gt;&gt;i;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; proref=reflect[count]&gt;&gt;j;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=propic&amp;1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; proref=proref&amp;1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (propic!=proref)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { correct=0;break;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (correct==1 &amp;&amp; outputn&gt;4) outputn=4;<br>}<br><br>nochange()<br>{int i,correct=1;<br>for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; if (picture[i]!=reflect[i]) correct=0;<br>if (correct==1 &amp;&amp; outputn&gt;6) outputn=6;<br>}<br><br>rotation90()<br>{long propic[9],procheck=0;int i,correct=1,count=1;<br>while(count&lt;=num)<br>{ for(i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; propic[i]=picture[i]; /* 复制原数*/<br>&nbsp; for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; if (num-count-i&gt;=0)<br>&nbsp;&nbsp;&nbsp; propic[i]=propic[i]&gt;&gt;(num-count-i);<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; propic[i]=propic[i]&lt;&lt;(count+i-num);<br>&nbsp;&nbsp;&nbsp; propic[i]=propic[i]&amp;((int)(pow(2,i)));}&nbsp;&nbsp;&nbsp; /* 将每个数第n位的值左移*/<br>&nbsp; procheck=0;<br>&nbsp; for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; procheck=propic[i]|procheck;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* 将每个数第n位移好的值进行合并，成为旋转后的数*/<br>&nbsp; if(procheck!=reflect[count-1])<br>&nbsp;&nbsp;&nbsp; {correct=0;break;}<br>&nbsp; count++;}<br>&nbsp; if (correct==1 &amp;&amp; combinate==0) outputn=1;<br>&nbsp; if (correct==1&amp;&amp; combinate==1)outputn=5;<br>}<br><br>rotation180()<br>{int i,count=0,correct=1;long procheck=0,propic;<br>&nbsp;&nbsp;&nbsp; while(count&lt;=num-1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; procheck=0;<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=num-1;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=picture[count]&gt;&gt;i;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=propic&amp;1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (propic==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {procheck&lt;&lt;=1;procheck=procheck+1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; procheck&lt;&lt;=1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (procheck!=reflect[num-count-1])<br>&nbsp;&nbsp;&nbsp; { correct=0;break;}<br>&nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (correct==1 &amp;&amp; outputn&gt;2 &amp;&amp; combinate==0) outputn=2;<br>&nbsp;&nbsp;&nbsp; if (correct==1 &amp;&amp; combinate==1) outputn=5;<br>}<br><br>rotation270()<br>{long propic[9],procheck=0;int i,j,correct=1,count=1;<br>while(count&lt;=num)<br>{ for(i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; propic[i]=picture[i];<br>&nbsp; for (i=0,j=(num-1);i&lt;=(num-1);i++,j--)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; propic[i]=propic[i]&gt;&gt;(num-count-j);<br>&nbsp;&nbsp;&nbsp; propic[i]=propic[i]&amp;((int)(pow(2,j)));}<br>&nbsp; procheck=0;<br>&nbsp; for (i=0;i&lt;=(num-1);i++)<br>&nbsp;&nbsp;&nbsp; procheck=propic[i]|procheck;<br>&nbsp; if(procheck!=reflect[num-count])<br>&nbsp;&nbsp;&nbsp; {correct=0;break;}<br>&nbsp; count++;}<br>if (correct==1 &amp;&amp; outputn&gt;3 &amp;&amp; combinate==0) outputn=3;<br>if (correct==1&amp;&amp; combinate==1)outputn=5;<br>}<br><br>combination()<br>{int i,count=0;long procheck=0,propic;<br>&nbsp;&nbsp;&nbsp; while(count&lt;=num-1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; procheck=0;<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=num-1;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=picture[count]&gt;&gt;i;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; propic=propic&amp;1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (propic==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {procheck&lt;&lt;=1;procheck=procheck+1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; procheck&lt;&lt;=1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; picture[count]=procheck;<br>&nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;combinate=1;<br>&nbsp;&nbsp;&nbsp; rotation90();<br>&nbsp;&nbsp;&nbsp; rotation180();<br>&nbsp;&nbsp;&nbsp; rotation270();<br>}<br><br>print()<br>{<br>&nbsp;&nbsp;&nbsp; fout=fopen("transform.out","w");<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d\n",outputn);<br>}<br><br>main()<br>{int l;<br>fin=fopen("transform.in","r");<br>fout=fopen("transform.out","w");<br>fscanf(fin,"%d\n",&amp;num);<br>scan();<br>rotation90();<br>if (outputn==7)<br>rotation180();<br>if (outputn==7)<br>rotation270();<br>if (outputn==7)<br>reflection();<br>if (outputn==7)<br>nochange();<br>if (outputn==7)<br>combination();<br>print();<br>return(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99884.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:15 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99884.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Friday the Thirteenth</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99882.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:14:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99882.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99882.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99882.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99882.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99882.html</trackback:ping><description><![CDATA[#include "stdio.h"<br><br>int n;<br><br>int plus(wochen,tag,plusday)<br>int wochen[7],tag,plusday;<br>{<br>&nbsp;&nbsp;&nbsp; tag+=plusday;<br>&nbsp;&nbsp;&nbsp; if (tag&gt;7) tag-=7;<br>&nbsp;&nbsp;&nbsp; wochen[tag]+=1;<br>&nbsp;&nbsp;&nbsp; return tag;<br>}<br><br>int leap(int y)<br>{<br>&nbsp;&nbsp;&nbsp; int yon;<br>&nbsp;&nbsp;&nbsp; yon=0;<br>&nbsp;&nbsp;&nbsp; if (y%4==0)<br>&nbsp;&nbsp;&nbsp; {if (y%100==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if(y%400==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yon=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else yon= 0;}<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yon=1;}<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yon=0;<br>&nbsp;&nbsp;&nbsp; return (yon);<br>}<br><br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int i,month,year,day,week[7];<br>&nbsp;&nbsp;&nbsp; FILE *fin;<br>&nbsp;&nbsp;&nbsp; FILE *fout = fopen ("friday.out", "w");<br>&nbsp;&nbsp;&nbsp; for (i=1;i&lt;=7;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {week[i]=0;}<br>&nbsp;&nbsp;&nbsp; fin=fopen("friday.in","r");<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%d\n",&amp;n);<br>&nbsp;&nbsp;&nbsp; year=0;<br>&nbsp;&nbsp;&nbsp; week[1]+=1;<br>&nbsp;&nbsp;&nbsp; day=1;<br>&nbsp;&nbsp;&nbsp; week[7]=0;<br>&nbsp;&nbsp;&nbsp; month=1;<br>&nbsp;&nbsp;&nbsp; while (year&lt;=(n-1))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (month&lt;=12)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (month==2)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (leap(year+1900)==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; day=plus(week,day,1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {day=plus(week,day,0);}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (month==4 || month==6 || month==9 || month==11)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; day=plus(week,day,2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; day=plus(week,day,3);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; month+=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; month=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; year+=1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; week[day]-=1;<br>&nbsp;&nbsp;&nbsp; for (i=1;i&lt;=6;i++)<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d ",week[i]);<br>&nbsp;&nbsp;&nbsp; fprintf(fout,"%d\n",week[7]);<br>exit(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99882.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:14 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99882.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Milking Cows</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99883.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:14:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99883.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99883.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99883.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99883.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99883.html</trackback:ping><description><![CDATA[#include "stdio.h"<br>#define MAX 10000<br>int start[MAX],stop[MAX],pro;<br>int n;&nbsp;&nbsp;&nbsp; <br>FILE *fin,*fout;<br><br>main()<br>{struct new<br>&nbsp;&nbsp;&nbsp; {int start,stop;}newline[MAX];<br>&nbsp;int i,j,count=0,arraymax=0,gapmax=0;<br>fin=fopen("milk2.in","r");<br>fout=fopen("milk2.out","w");<br>fscanf(fin,"%d\n",&amp;n);<br>for (i=0;i&lt;n;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fscanf(fin,"%ld %ld\n",&amp;start[i],&amp;stop[i]);<br>&nbsp;&nbsp;&nbsp; }<br>for (i=0;i&lt;n-1;i++)<br>&nbsp;&nbsp;&nbsp; {for(j=i+1;j&lt;n;j++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (start[i]&gt;start[j])<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pro=start[i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; start[i]=start[j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; start[j]=pro;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pro=stop[i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stop[i]=stop[j];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stop[j]=pro;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>newline[0].start=start[0];newline[0].stop=stop[0];<br>for (i=0;i&lt;n-1;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (start[i+1]&lt;=newline[count].stop)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (stop[i+1]&gt;newline[count].stop)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {newline[count].stop=stop[i+1];}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newline[count].start=start[i+1];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newline[count].stop=stop[i+1];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>for (i=0;i&lt;count;i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (arraymax&lt;(newline[i].stop-newline[i].start)) arraymax=newline[i].stop-newline[i].start;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (gapmax&lt;(newline[i+1].start-newline[i].stop)) gapmax=newline[i+1].start-newline[i].stop;<br>&nbsp;&nbsp;&nbsp; }<br>if (arraymax&lt;(newline[i].stop-newline[i].start)) arraymax=newline[i].stop-newline[i].start;<br>fprintf(fout,"%d %d\n",arraymax,gapmax);<br>return(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99883.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:14 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99883.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Broken Necklace</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99881.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:13:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99881.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99881.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99881.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99881.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99881.html</trackback:ping><description><![CDATA[#include "stdio.h"<br>main()<br>{<br>&nbsp;&nbsp;&nbsp; int promax,max,n,cut,count,turnover;<br>&nbsp;&nbsp;&nbsp; char color[350],next,head;<br>&nbsp;&nbsp;&nbsp; FILE *fin=fopen("beads.in","r");<br>&nbsp;&nbsp;&nbsp; FILE *fout=fopen ("beads.out","w");<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%d\n",&amp;n);<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%s\n",color);<br>&nbsp;&nbsp;&nbsp; count=0; max=0;<br>&nbsp;&nbsp;&nbsp; head=color[count];<br>&nbsp;&nbsp;&nbsp; promax=1; cut=0;<br>&nbsp;&nbsp;&nbsp; turnover=0;<br>&nbsp;&nbsp;&nbsp; while (turnover&gt;=0 &amp;&amp; promax!=n)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (count&lt;n-1) count++; else {count=0;turnover=1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (head=='w' &amp;&amp; color[count]!='w') head=color[count];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (head==color[count] ||color[count]=='w') promax+=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {if (cut==0) {cut=count;head=color[count];promax+=1;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {if (cut&gt;0 &amp;&amp; max&lt;promax)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {max=promax; promax=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=cut; head=color[count];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (color[count-1]=='w')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {count--;promax++;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=cut; cut=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (turnover==1) turnover=-1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {promax=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=cut;head=color[count];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (color[count-1]=='w')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {count--;promax++;}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=cut; cut=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (turnover==1) turnover=-1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (promax==n) fprintf(fout,"%d\n",promax);<br>&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; fprintf(fout,"%d\n",max);<br>&nbsp;&nbsp;&nbsp; exit(0);<br>}<br><img src ="http://www.cppblog.com/laysent/aggbug/99881.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:13 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99881.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO-Your Ride Is Here</title><link>http://www.cppblog.com/laysent/archive/2009/10/31/99880.html</link><dc:creator>laysent</dc:creator><author>laysent</author><pubDate>Sat, 31 Oct 2009 02:12:00 GMT</pubDate><guid>http://www.cppblog.com/laysent/archive/2009/10/31/99880.html</guid><wfw:comment>http://www.cppblog.com/laysent/comments/99880.html</wfw:comment><comments>http://www.cppblog.com/laysent/archive/2009/10/31/99880.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/laysent/comments/commentRss/99880.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/laysent/services/trackbacks/99880.html</trackback:ping><description><![CDATA[#include &lt;stdio.h&gt;<br>main()<br>{<br>&nbsp;&nbsp;&nbsp; FILE *fin&nbsp; = fopen ("ride.in", "r");<br>&nbsp;&nbsp;&nbsp; FILE *fout = fopen ("ride.out", "w");<br>&nbsp;&nbsp;&nbsp; char product[7], comet[7];<br>&nbsp;&nbsp;&nbsp; int k,i,j,promod,commod;<br>&nbsp;&nbsp;&nbsp; long pro,com;<br>&nbsp;&nbsp;&nbsp; fscanf (fin, "%s\n", product);<br>&nbsp;&nbsp;&nbsp; fscanf(fin,"%s\n",comet);<br>&nbsp;&nbsp;&nbsp; k=strlen(product);<br>&nbsp;&nbsp;&nbsp; pro=1;<br>&nbsp;&nbsp;&nbsp; com=1;<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=k;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pro=pro*(product[i]-64);<br>&nbsp;&nbsp;&nbsp; j=strlen(comet);<br>&nbsp;&nbsp;&nbsp; for (i=0;i&lt;=j;i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; com*=(comet[i]-64);<br>&nbsp;&nbsp;&nbsp; promod=pro % 47;<br>&nbsp;&nbsp;&nbsp; commod= com % 47;<br>&nbsp;&nbsp;&nbsp; if (promod == commod) fprintf(fout, "GO\n");<br>&nbsp;&nbsp;&nbsp; else fprintf(fout,"STAY\n");<br>&nbsp;&nbsp;&nbsp; exit (0);<br><br>&nbsp;&nbsp;&nbsp; }<br><img src ="http://www.cppblog.com/laysent/aggbug/99880.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/laysent/" target="_blank">laysent</a> 2009-10-31 10:12 <a href="http://www.cppblog.com/laysent/archive/2009/10/31/99880.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>