zoj 1005 Jugs

摘要: 本来以为今天中午这题不会写出来了,不过幸运AC了;先说一下,我知道这题好的方法是用搜索DFS(BFS貌似不爽吧);不过我还不会用DFS,确切说是不敢用没有大胆尝试,DFS,一定要试着写一写;说一下我的原理吧:小杯子往大杯子里pour,只要小杯子能装下,大的一定也能,所以我只让小的pour大的,并且只检验大的杯子里的数是否是目标值(应该迟早能达到目标值,只不过这种做法不是最优解而已);还有,分别用x,y来表示小大杯子里的实际水量很有助于理解哦#include<stdio.h>#include<stdlib.h>#include<string.h>#includ 阅读全文
posted @ 2011-08-19 13:52 java课程设计例子 阅读(166) 评论(0) 推荐(0)

zoj 1914 Arctic Network

摘要: 找最小生成树的倒数第几长边的问题1,读入数据的处理,最终处理为结构体形式2,快排................................3,并查集找结点,并记录边长大小4,输出所求数据#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>typedef struct Tedge{ int from,to; int dist;}edge;edge dis[500*500]; //记录from点到to点的距离int ans[500+10]; //记录距离in. 阅读全文
posted @ 2011-08-19 10:15 java课程设计例子 阅读(124) 评论(0) 推荐(0)

zoj 1789 The Suspects

摘要: 这道题是并查集的题,写过这道题之后,我明白了一点,就是从根上改变所属father域#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int p[30000+100];int a[30000+100];int find(int x){ if(p[x] == x) return x; p[x] = find(p[x]); return p[x];}int main(){ int n,m,k,i,count,temp; while(scanf("%d%d& 阅读全文
posted @ 2011-08-19 10:11 java课程设计例子 阅读(164) 评论(0) 推荐(0)

nyoj 44 子串和

摘要: 这道题竟然纠结了我好长时间,先是,我尝试了n多变量,WA的很无语当然我知道那是因为我的原理不正确,有的情况没有考虑;后来才用的下边的方法,简单易行,不过数组开得有点小虾仁,这个题使我不敢再小嘘任何题#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<limits.h>#define maxn 1000000int a[maxn+10];int main(){ int t,n,i; scanf("%d",& 阅读全文
posted @ 2011-08-19 08:48 java课程设计例子 阅读(112) 评论(0) 推荐(0)