2011年8月30日

hdu3916Sequence Decomposition贪心

摘要: hdu3916Sequence Decomposition贪心解:(引)比如一个序列2 3 4 3 3 1如何拆成门函数分量使得长度尽量平均呢? 直观的想法是在消的过程中使序列尽量平均。首先想到是左边第一个肯定要拆成2个门函数且应使其尽可能长,但也不是越长越好。如果a[i] <= a[i+1] 那么消掉a[i]的时候,a[i+1]消掉肯定没坏处,因为如果不消,不仅可能使答案变小,而且序列也会变的更加不平均如果a[i] > a[i+1] 则本着使序列越来越平均的思想,消掉a[i]的时候自然是不要消掉a[i+1]了。上述样例采用该贪心方法的过程是2 3 4 3 3 1 消(1,3)1 阅读全文
posted @ 2011-08-30 00:53 4.5.6 阅读(133) 评论(0) 推荐(0) 编辑

hdu2863Top Shooter

摘要: 贪心:枚举时间用范围最大的打高度最小的先按时间后按高度从低到高排列View Code #include<iostream>#include<queue>using namespace std;int sni[51];const int INF=10000000;int MIN,n,m;struct node { int t,h; node(){}; node(int _t,int _h):t(_t),h(_h){}; friend bool operator<(const node &a,const node&b) { if(a.t!=b.t)re 阅读全文
posted @ 2011-08-30 00:47 4.5.6 阅读(115) 评论(0) 推荐(0) 编辑
2011年8月29日

hdu3974Assign the task

摘要: View Code /*hdu3974Assign the task并查集建立集合:v u表示v是u的下属T x y 当x被分配到y任务时,他和下属的任务立刻变更为yC x 询问x当前所分配的任务task[i]表示i最后直接接到分配的任务 num[i]表示i接到任务的序号当询问x时 只要找到祖先中最迟分配到的任务,即num[i]最大相对应的task[i]*/#include<iostream>#include<algorithm>using namespace std;const int maxn=50001;int pre[maxn],vis[maxn],task[m 阅读全文
posted @ 2011-08-29 23:50 4.5.6 阅读(163) 评论(0) 推荐(0) 编辑
2011年8月28日

hdu3926Hand in Hand

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3926View Code hdu3926Hand in Hand/*题意:判断两幅图是否同构 图中即判断图中环和链的个数是否相同 环和链是否一一相对应利用并查集 一个集合中若人数num[]和拉手对手p[]相等 则为环,num[]==p[]+1则为链*/#include<iostream>#include<set>#include<algorithm>using namespace std;const int maxn=10001;int pre[maxn],p[maxn], 阅读全文
posted @ 2011-08-28 21:20 4.5.6 阅读(169) 评论(0) 推荐(0) 编辑
2011年8月12日

线段树无止尽版

摘要: 最近在陆陆续续学习线段树 把学习的点滴汇集起来 也许将来对自己和别人都有所帮助!!首先特别鸣谢NotOnlySuccess(http://www.notonlysuccess.com/?p=978) 我视这位神明为线段树的导师 他的【完全版】造福全人类Hdu1754 I hate it单点更新:最最基础的线段树,只更新叶子节点,然后把信息用PushUP(int r)这个函数更新上来View Code #include<iostream>#include<algorithm>using namespace std;int MAXN[4000001],d[4000001]; 阅读全文
posted @ 2011-08-12 12:23 4.5.6 阅读(262) 评论(0) 推荐(1) 编辑
2011年6月29日

hdu1150Machine Schedule

摘要: #include<iostream>#include<cstring>#include<stdio.h>using namespace std;int m,n,k;/*hdu1150 Machine Schedule最小点覆盖=最大匹配数,把任务看做匹*/int Link[202][202],vis[202],yM[202];bool find_path(int u)//匈牙利算法{ for(int v=1;v<=m+n;v++) { if(!vis[v]&&Link[u][v]) { vis[v]=1; if(yM[v]==-1||f 阅读全文
posted @ 2011-06-29 22:40 4.5.6 阅读(155) 评论(0) 推荐(0) 编辑
2011年5月14日

zju1024Calendar Game

摘要: #include<iostream>#include<cstring>using namespace std;int maxd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//每个月最多天数int iswin[102][13][32];//以该天起始,亚当是否会赢 1会赢 0 会输 -1还没计算过int judge(int y,int m,int d){ int win=0; if(y==101&&m==11&&d==4)return 0;//若Eve成功 if(y>101||(y==10 阅读全文
posted @ 2011-05-14 12:56 4.5.6 阅读(201) 评论(0) 推荐(0) 编辑
2011年5月11日

zjut1698Coins

摘要: /*多重背包zjut 1698 Coins 思路:根据每个coin的x y值大致得出每种coin最多可取几个,然后用二进制处理产生新的coin,将问题转化为01背包状态转移:dp[j][k]=min(dp[j-xx[i]][k-yy[i]]+cost[i],dp[j][k]);*/#include<iostream>#include<cmath>#include<algorithm>using namespace std;int m,s;int x[101],y[101],dp[301][301],vis[301][301];int xx[100001],y 阅读全文
posted @ 2011-05-11 23:02 4.5.6 阅读(136) 评论(0) 推荐(0) 编辑
2011年5月8日

zjut1684AirCraft

摘要: http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1684AirCraft Time Limit:1000MS Memory Limit:32768KDescription:LCS has an aircraft, he can use some specific commands to make his aircraft to move. To simple the problem, you can assume the aircraft just move on the 2D-Plane.There are four commands :fd x 阅读全文
posted @ 2011-05-08 10:26 4.5.6 阅读(164) 评论(0) 推荐(0) 编辑
2011年5月7日

zjut1689联盟

摘要: http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1689联盟 Time Limit:1000MS Memory Limit:32768KDescription:某大陆上有n个独立的国家,它们没有组成任何联盟。但从某一天开始,1号国家将某国拉拢过去作为联盟,然后2号国家也拉拢某国,然后3号。。。。一直到n号国家。如果拉拢的国家已有联盟,则将它所属联盟一起拉拢过来,形成新的联盟。当n次拉拢结束之后,求1号国家的联盟国有几个。Input:有多组测试数据。每组数据有两行,第一行为n(1<=n<=350000),第二行有n个数,分别表示n个国家拉 阅读全文
posted @ 2011-05-07 18:07 4.5.6 阅读(166) 评论(0) 推荐(0) 编辑