随笔分类 -  acm

微软编程之美初赛第一场第一题焦距
摘要:擦,太失败了,才做出来第一题,第二题找不到自己错在哪里,感觉题目都还好。还是自己太菜了,需要努力。小数据是自己写的,大数据让老婆写了,这题充分体现了自己基础差,读入到转换成double一定要多走弯路,基础是王道啊~第一题代码#include#include#include#includeusing ... 阅读全文

posted @ 2014-04-19 22:17 云在心 阅读(181) 评论(0) 推荐(0)

微软编程一小时
摘要:由于通知的太尴尬,那时候人已在上海,所以没时间做,昨天晚上看了一下题目,自己写了一下,但是不能提交了,就放在这里让大家给我检查检查。第一题,不知道是不是想的太复杂了,我把每个表达式都表示成分数的形式,然后减去9,然后进行比较。为了分数的加减以及比较,所以写了一个分数结构体,提供+,-, 2 using namespace std; 3 struct fenshu{ 4 int fenzi; 5 int fenmu; 6 fenshu(){ 7 fenzi=1; 8 fenmu=1; 9 } 10 fensh... 阅读全文

posted @ 2014-04-09 16:44 云在心 阅读(428) 评论(2) 推荐(0)

uva 10192 - Vacation
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 int maxlen[102][102]; 6 void lsc(string a,string b){ 7 for(int i=1;i=maxlen[i][j-1])13 maxlen[i][j]=maxlen[i-1][j];14 else15 maxlen[i][j]=maxlen[i][j-1];16 }17 }18 }19 i... 阅读全文

posted @ 2014-03-18 12:27 云在心 阅读(182) 评论(0) 推荐(0)

uva 10066 - The Twin Towers
摘要:就按照传统的方法求。 1 #include 2 #include 3 using namespace std; 4 int m,n,maxlen[102][102]; 5 void lcs(int a[],int b[]){ 6 for(int i=1;i=maxlen[i][j-1])12 maxlen[i][j]=maxlen[i-1][j];13 else14 maxlen[i][j]=maxlen[i][j-1];15 }16 } 17 ... 阅读全文

posted @ 2014-03-18 12:24 云在心 阅读(146) 评论(0) 推荐(0)

动态规划1--最长公共子序列
摘要:最近在做动态规划的题目,这里的题目绝对是acm的一个门槛,对你的编程能力,逻辑能力,算法能力都是一个考验。我不幸已经在门槛上摔到了。 动态规划的学习是一个长期的过程,如果只是做题不进行理论学习,我感觉是非常艰难,属于事半功倍类型。所以一边要进行题目上的训练,一边也要总结,在理论上进行巩固。 先从最近的几题入手,最长公共子序列。uva-103,111,10066,10192个人感觉都是这类型的。 我看了几篇牛人也的博客,感觉自己描述可能反倒不能理解,所以选取最佳的一篇放在这里供大家学习。 http://www.cnblogs.com/huangxincheng/archive... 阅读全文

posted @ 2014-03-18 12:23 云在心 阅读(159) 评论(0) 推荐(0)

uva 674 - Coin Change
摘要:这题调试了好久啊。不要一开始就想着动态规划,慢慢做就可以做出来了,要记着给d[i][1]赋值。#include#includeusing namespace std;long long d[6][8000];int coin[6]={0,1,5,10,25,50};long long dp( int a,int k){ if(d[a][k]>0) return d[a][k]; d[a][k]=0; for(int i=0;i>m){ if(m==0){ cout<<0<<endl; continue; ... 阅读全文

posted @ 2014-03-05 14:50 云在心 阅读(147) 评论(0) 推荐(0)

uva 103 - Stacking Boxes
摘要:这一题和上一题类似,只不过要保存最长序列而已,可以知道在刘汝佳老师书中只要记录状态d[i]的前一个即可。 1 #include 2 #include 3 using namespace std; 4 int dj[100][100],num[100][100],d[100]; 5 int m,n; 6 int prenum[100]; 7 int distanc(int a){ //动态规划的方法仿照上一题 8 if(d[a]>-1) 9 return d[a];10 for(int i=0;i>m>>n){29 for(in... 阅读全文

posted @ 2014-03-03 13:00 云在心 阅读(145) 评论(0) 推荐(0)

uva 111 - History Grading
摘要:这题的提议很容易理解错,一开始按照他的sample int 和 out都无法推理出。假设有A B C D四个事件,发生顺序 4 2 3 1 是指 第一个事件是第四个发生的,即 A事件是第四位发生,所以事件的发生顺序为 D B C A。这题用动态规划的思想做,不过感觉自己写的不是很正宗。 1 #include 2 using namespace std; 3 int numevents[21]; 4 int d[21]; //假设状态为d,即按照学生提供的事件顺序(不是他的那串输入数字),d[i]表示第i个数字能够达到的最长序列 5 int path[21]; 6 int temp[21]; 7 阅读全文

posted @ 2014-02-27 15:13 云在心 阅读(179) 评论(0) 推荐(0)

uva 10110 - Light, more light
摘要:这题题目中有个单词打错了害我题意理解了好几天,只能打dota2消遣,其中 “whose serial is divisable by i ” 其实是 "whose serial is divisible by i "这题要注意的地方是 2^32 -1 , 整个题目很简单就判断一个数是否是完全平方数 1 #include 2 #include 3 using namespace std; 4 int main(){ 5 unsigned long n; 6 while(cin>>n){ 7 if(!n) 8 break; 9 ... 阅读全文

posted @ 2014-01-27 14:52 云在心 阅读(171) 评论(0) 推荐(0)

uva 575 - Skew Binary
摘要:这是一题进制转换问题,因为最大为2^31-1,所以只要建立一个数组把2^1-1 到2^31-1先保存就是一个很简单的问题 1 #include 2 #include 3 #include 4 using namespace std; 5 int main(){ 6 long long kth[32]; 7 kth[0]=1; 8 for(int i=1;i<32;i++){ 9 kth[i]=(kth[0]=kth[0]<<1)-1;10 }11 string temp;12 while(getline(cin,temp)){1... 阅读全文

posted @ 2014-01-23 11:27 云在心 阅读(162) 评论(0) 推荐(0)

uva Maths - Number Theory
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100这是将要做的题目的网址,上一章还有几题没做出来,先不管了,开始新的一章,数论,希望能一切顺利 阅读全文

posted @ 2014-01-21 16:57 云在心 阅读(91) 评论(0) 推荐(0)

uva 10014 - Simple calculations
摘要:尼玛,这题太搞了,已经推出公式了,还是不对,看了网上正确的代码也没发现自己错的地方,尼玛这是网上的 1 #include 2 #include 3 void main() 4 {double c[3001],s[3001],x,y; 5 int n,i,t; 6 scanf("%d",&t); 7 while (t--) 8 { 9 scanf("%d",&n);10 scanf("%lf%lf",&x,&y);11 for (i=1;i 2 #include 3 using namespace std 阅读全文

posted @ 2014-01-21 16:45 云在心 阅读(158) 评论(0) 推荐(0)

uva 10970 - Big Chocolate
摘要:水题。。。1 #include2 using namespace std;3 int main(){4 int m,n;5 while(cin>>m>>n){6 cout<<m-1+(n-1)*m<<endl;7 }8 } 阅读全文

posted @ 2014-01-13 10:20 云在心 阅读(89) 评论(0) 推荐(0)

uva 10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?
摘要:感觉这是一道纯数学题,正好复习了一下平方和公式以及立方和公式4次方和没有查到只能用计算机来做,为了好看,我平方和以及立方和也用for来做,运行速度还是挺快的,这里要注意由于数比较大很可能越界,所以要用longlong 1 #include 2 using namespace std; 3 long long n4[101]; 4 long n3[101]; 5 long n2[101]; 6 int main(){ 7 n4[0]=n3[0]=n2[0]=0; 8 for(int i=1;i>N){17 long long temp=(N+1)*N/2;18 ... 阅读全文

posted @ 2014-01-12 20:58 云在心 阅读(158) 评论(0) 推荐(0)

uva 10719 - Quotient Polynomial
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int a[10000]; 8 int b[10000]; 9 int main(){10 int k;11 while(cin>>k){12 getchar();13 string l;14 getline(cin,l);15 istringstream iss(l);16 int i=0;17 for(string te... 阅读全文

posted @ 2014-01-11 10:56 云在心 阅读(170) 评论(0) 推荐(0)

uva 11044 - Searching for Nessy
摘要:水题中的水题。。。。#includeusing namespace std;int main(){ int n,m; int t; cin>>t; while(t--){ cin>>n>>m; int temp1=n/3; int temp2=m/3; cout<<temp1*temp2<<endl; }} 阅读全文

posted @ 2014-01-10 21:33 云在心 阅读(99) 评论(0) 推荐(0)

uva 10790 - How Many Points of Intersection?
摘要:这题方法很简单,但是要注意数据类型要用longlong,题目中给出了是64bit的 1 #include 2 using namespace std; 3 int main(){ 4 long a,b,temp=1; 5 while(cin>>a>>b){ 6 if(!a&&!b) 7 break; 8 long long sum=1; 9 if(a<2||b<2){10 cout<<"Case "<<temp++<<": 0"<<endl;11 cont 阅读全文

posted @ 2014-01-10 21:16 云在心 阅读(145) 评论(0) 推荐(0)

uva 10499 - The Land of Justice
摘要:感觉很简单的一题,但是wa了两次,还是看了网上的代码才知道,虽然N是int型的,但是25*n就不一定是了,改成long就行了#includeusing namespace std;int main(){ long n; while(cin>>n){ if(n<0) break; if(n==1){ cout<<"0%"<<endl; continue; } cout<<n*25<<"%"<<endl; }} 阅读全文

posted @ 2014-01-10 20:18 云在心 阅读(136) 评论(0) 推荐(0)

uva 846 - Steps
摘要:wa了两次才纠正,虽然想法对了,还是要自己先多测几组数据#include#includeusing namespace std;int main(){ int x,y; int n; cin>>n; while(n--){ cin>>x>>y; if(x==y){ cout<<"0"<<endl; continue; } int n = (int)sqrt((double)(y-x)); if(n==1) cout<<y-x<<endl... 阅读全文

posted @ 2014-01-10 17:20 云在心 阅读(151) 评论(0) 推荐(0)

uva 573 - The Snail
摘要:很简单,不过还是wa了几次,才做对#includeusing namespace std;int main(){ int h,speed,slide,per; while(cin>>h>>speed>>slide>>per){ if(!h&&!speed&&!slide&&!per) break; h*=100; speed*=100; slide*=100; int d=speed*per/100; int height=0; for(int i=0;;... 阅读全文

posted @ 2014-01-10 14:44 云在心 阅读(126) 评论(0) 推荐(0)

导航