09 2011 档案

摘要:View Code #include<stdio.h>#include<string.h>#define max 100010 int b[max],c[max];__int64 x[max],y[max];int a[max];int lowbit(int x){ return x&(-x);}void update(int arr[],int x){ while(x<=max) { arr[x]++; x+=lowbit(x); }}__int64 sum(int arr[],int x){ __int64 ans=0; wh... 阅读全文
posted @ 2011-09-29 17:15 Because Of You 阅读(289) 评论(0) 推荐(0)
摘要:题目意思,可以从A走到B当且仅当B到终点的最短路径小于A到终点的最短路径问一共存在几条这样的路径我用dijkstra各做了一遍,呵呵个中细节还需细细体味啊View Code #include<stdio.h>#include<queue>#include<string.h>using namespace std;const int INF = 9999999;struct NODE{ int v,w; int next;}list[10000000];int tot;int head[1010];int dis[1010];int vis[1010];int 阅读全文
posted @ 2011-09-26 15:19 Because Of You 阅读(282) 评论(0) 推荐(0)
摘要:一个人的旅行Time Limit : 1000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 28Accepted Submission(s) : 7Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽 阅读全文
posted @ 2011-09-26 12:26 Because Of You 阅读(435) 评论(0) 推荐(0)
摘要:题目任意给出四个点,求出到这四个点的距离之和最小的点到这四个点的距离若四边形为凸的,费马点为对角线交点,否则为凹的那点证明很简单,把要证明的那点与其他顶点连起来,再任取一点,证明这点到四个顶点的距离比原来那点长即可View Code #include<stdio.h>#include<math.h>#include<string.h>const double esp=1e-8;struct point{ double x,y;}a[10];struct line { double a,b,c;};double min(double a,double b){ 阅读全文
posted @ 2011-09-24 20:35 Because Of You 阅读(496) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>int c[50010];char str[50010];int n,m;int lowbit(int x){ return x&(-x);}void update(int x,int d){ while(x<=n) { c[x]+=d; x+=lowbit(x); }}int sum(int x){ int ans=0; while(x>0) { ans+=c[x]; x-=lowbit(x); } ... 阅读全文
posted @ 2011-09-23 21:51 Because Of You 阅读(358) 评论(0) 推荐(0)
摘要:View Code #include<queue>#include<iostream>#include<vector>using namespace std;struct mycmp{ bool operator()(const int &a,const int &b) { return a>b; }};//这里表示从小到大排列,最小的数在队头,随时准备走出队列int main(){ int n,k,val; char str[5]; int count; while(scanf("%d%d",&n,& 阅读全文
posted @ 2011-09-23 15:25 Because Of You 阅读(862) 评论(1) 推荐(0)
摘要:Fruit NinjaTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 374Accepted Submission(s): 197Problem DescriptionRecently, dobby is addicted in the Fruit Ninja. As you know, dobby is a free elf, so unlike other elves, he could do whatever he wants.But t 阅读全文
posted @ 2011-09-23 12:00 Because Of You 阅读(451) 评论(0) 推荐(0)
摘要:请看几段区间1 --------------2 -------------3 --------4 -----先按y排序,再按x排序;排好序后就跟stars那题一样了一次遍历排序后的数组,由于比当前遍历元素strong的区间只可能存在于已经遍历过的元素中;所以我们可以放心大胆的直接对树状数组求和然后向后更新树状数组中统治x的点上的值,因为那些位置都多了一个比 以他们为左端点的区间 强壮 的区间;然后注意一下相同区间的处理即可跑了1157ms的代码。其实感觉也蛮快的了*-*View Code #include<stdio.h>#include<string.h>#inclu 阅读全文
posted @ 2011-09-20 23:49 Because Of You 阅读(436) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;#define N 1001const double pi=acos(-1.0);struct point { int x,y;}node[N];int s[N];int top;int cmp(point a,point b){ if(a.y==b.y) return a.x<b.x; return a.y<b.y;}double ch 阅读全文
posted @ 2011-09-17 21:29 Because Of You 阅读(215) 评论(0) 推荐(0)
摘要:其实不管什么DP,本质思想都是不变的,围绕着最优子结构展开思路,最终记录下最优的结果,所以写好状态转移,处理好边界问题,还是关键手段。状态:dp[i][j]表示以i为根的子树孤立出 j 个点要去掉的最少的边,在树上的动态规划一般都是父结点和子节点的关系,所以在思考状态转移时时应该尽量把父结点的子节点考虑进去分别以不同的点为根进行深搜先要想到我们最后要得到的结果应该是dp[i][p]中的最小值而dp[i][j]是从dp[u][k]和dp[i][j-k]推过来的,u为i的子节点还有就是以i为根和以i的子节点为u根时,dp[u][k]+dp[i][j-k]多加了两次他们之间的边,所以要减去2即dp[ 阅读全文
posted @ 2011-09-17 09:54 Because Of You 阅读(243) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>int map[105][105];int main(){ int n,m,a,b; int i,j,k; scanf("%d%d",&n,&m); memset(map,0,sizeof(map)); for(i=0;i<m;i++) { scanf("%d%d",&a,&b); map[a][b]=1; } for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j 阅读全文
posted @ 2011-09-16 15:51 Because Of You 阅读(162) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#define MAXN 101000#define INF 2000000struct NODE{ int v; int w; NODE *next;}edge[MAXN],redge[MAXN],temp[MAXN*2];int pos=0;int ecost[MAXN];int N,M,W,s,Q[MAXN];bool vis[MAXN];void spfa(int dir)//0为正向,1为反向{ int head,rear,u,i; NODE*ptr; hea... 阅读全文
posted @ 2011-09-16 15:32 Because Of You 阅读(184) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>int prime[10000];int vis[10000];int ans;int a[10000];void init(){ int i,j; int n=12997; memset(vis,0,sizeof(vis)); for(i=2;i<=n;i++) for(j=i*2;j<=n;j+=i) vis[j]=1; ans=1; for(i=2;i<=n;i++) { if... 阅读全文
posted @ 2011-09-14 15:27 Because Of You 阅读(245) 评论(0) 推荐(0)
摘要:水题,不解释View Code #include<stdio.h>#include<string.h>const int INF = 9999999;int n,r,map[250][250];char city[250][30];int num;int max(int a,int b){ return a>b?a:b;}int min(int a,int b){ return a<b?a:b;}int find(char s[]){ int i; for(i=0;i<num;i++) if(strcmp(city[i],s)==0) ... 阅读全文
posted @ 2011-09-14 14:48 Because Of You 阅读(144) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<math.h>#include<iostream>using namespace std;typedef __int64 lld;void gcd(lld a,lld b,lld &d,lld &x,lld &y){ if(!b) {d=a;x=1;y=0;} else { gcd(b,a%b,d,y,x);y-=x*(a/b);}}int main(){ lld x,y,m,n,l; lld a,b,c,d,g,s; scanf("%I64d%I64d 阅读全文
posted @ 2011-09-12 20:50 Because Of You 阅读(241) 评论(0) 推荐(0)
摘要:现在还不怎么适应比赛的节奏啊,二分边长即可,余弦定理求角度即可,注意,要先判断所选取的边是否合法View Code #include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>const double pi = acos(-1.0);const double expn=1e-8;double a[110];int n;double get_angel(double x,double y,double z){ return acos((x*x+y*y-z*z)/(2*x* 阅读全文
posted @ 2011-09-12 15:28 Because Of You 阅读(269) 评论(0) 推荐(0)
摘要:直接在矩阵上进行floyd在判断即可View Code #include<stdio.h>int map[110][110];int vis[110][110];int main(){ int t,n,i,j,k; int cases=1; scanf("%d",&t); while(t--) { scanf("%d",&n); int tot=n*(n-1); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { scanf(... 阅读全文
posted @ 2011-09-11 21:39 Because Of You 阅读(163) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<math.h>#include<string.h>struct PEAK{ double x,h;}p[1100];struct bit{ double x,v,m;}pat[1100];int main(){ int G=20; double h; int t,cases=1,i,j,n,m,w; scanf("%d",&t); while(t--) { double v0=0,temp; scanf("%d%d%d",&n,&a 阅读全文
posted @ 2011-09-11 21:19 Because Of You 阅读(312) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>const int MAX=8010;#define L(x) x<<1#define R(x) x<<1|1#define MID(x,y) (x+y)>>1struct { int l,r,col;}node[MAX*4];int seg[MAX],col[MAX];void init(){ memset(node,0,sizeof(node)); memset(col,-1,sizeof(col));}void build(int t,in 阅读全文
posted @ 2011-09-08 20:52 Because Of You 阅读(394) 评论(0) 推荐(1)
摘要:View Code #include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#define maxn 1005const int inf =1000000000;struct Edge{ int u,v; __int64 cost;}E[maxn*maxn];int nv,ne;int pre[maxn],ID[maxn],vis[maxn];__int64 In[maxn];int ansi;//最小树形图邻接表版本,三步走,找最小入弧,找有向环,缩环为点__in 阅读全文
posted @ 2011-09-07 12:54 Because Of You 阅读(999) 评论(0) 推荐(1)
摘要:需要注意,因为增加一个零点,最后总点数要加1;此模板的边和点都从0开始计数废话一句,厚积方能薄发啊。View Code #include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#define maxn 1005const int inf =1000000000;struct Edge{ int s,t; int cost;}edge[maxn*maxn];struct node{ int x,y,z;}a[maxn];int E,nv,ne;int pre[maxn 阅读全文
posted @ 2011-09-06 20:07 Because Of You 阅读(327) 评论(0) 推荐(0)
摘要:记住,这是china算法,呵呵,一丝悲哀,又有一丝欣慰第一次做,用的是矩阵版本的,但貌似对于数据更大的情况要用邻接表的,继续学习View Code #include<stdio.h>#include<math.h>#include<string.h>#define INF 100000000#define min(a,b) a<b?a:bint n,m;double map[110][110];int vis[110],pre[110];int circle[110]; struct { int x,y;}node[110];double dist(i 阅读全文
posted @ 2011-09-06 11:44 Because Of You 阅读(294) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<algorithm>using namespace std;int l,n,m;int dis[500005];int judge(int x){ int now=0,pos=0,jump=0; while(now<l) { now+=x; while(now>=dis[pos+1]) pos++; now=dis[pos]; jump++; } return jump;}int main(){ int i,res,min; ... 阅读全文
posted @ 2011-09-04 19:51 Because Of You 阅读(176) 评论(0) 推荐(0)
摘要:有n台坏掉电脑,有两种操作,O表示修好一台电脑,修好后就可以更新与其它已修好的电脑的关系了,即如果与某台已经修好的电脑在可以连接的范围内,则两台电脑建立联系,另一种操作是询问,直接找根节点就好。。。。是水题啊,不过有一些细节要注意啊。View Code #include<stdio.h>#include<string.h>#define MAX 1050struct node{ int x,y;}com[MAX];int fa[MAX],repaired[MAX];int n,d,tot;void init(){ for(int i=1;i<=n;i++) fa[ 阅读全文
posted @ 2011-09-04 19:02 Because Of You 阅读(200) 评论(0) 推荐(0)
摘要:两种操作,叠立方体,数某个立方体下面有几个立方体;操作次数很多,采用并查集实现其中above[i]表示在 i 上面的立方体个数sum[i]表示根节点i下面的立方体个数,包括i所以x下面的立方体个数就等于x的根节点下面的总的立方体个数减去x上面的立方体个数(直接记录x的下面的立方体个数貌似有难度)View Code #include<stdio.h>#include<string.h>#define MAX 30010int fa[MAX],sum[MAX],above[MAX];void init(){ for(int i=0;i<=30000;i++) { fa 阅读全文
posted @ 2011-09-04 16:53 Because Of You 阅读(377) 评论(0) 推荐(0)
摘要:一般的种类并查集,只不过犯了点小错误,一直TLEView Code #include<stdio.h>#include<string.h>int fa[100005],rank[100005],n;void init(){ for(int i=1;i<=n;i++) { fa[i]=i; rank[i]=0; }}int find(int x){ if(fa[x]==x) return x; int tx=find(fa[x]); rank[x]=(rank[x]+rank[fa[x]])%2; fa[x]=tx; ... 阅读全文
posted @ 2011-09-04 16:07 Because Of You 阅读(214) 评论(0) 推荐(0)
摘要:View Code //dp[i]表示以第i个长方体结尾的最大高度(先排好序的)//虽说不难,但一些细节能让人崩溃,以后一定要注意//刚开始想到的状态为前i个长方体所能产生的最大高度,但亲注意://ps:这是比赛时想到的状态,悲剧就是这么发生的//如果dp[i]如上定义,那么当用第i个长方体往前覆盖时,应该在原来的路径上覆盖,而不是从i-1->1;//因此这种方法正确性貌似有待证明#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;__int64 dp[10 阅读全文
posted @ 2011-09-03 20:59 Because Of You 阅读(221) 评论(0) 推荐(0)
摘要:View Code int dist[N<<1],mx[N],my[N],m,n;vector<int> map[N];int que[N<<1],head,tail;int bfs(){ int i; head=0;tail=-1; for(i=1;i<=n;i++) if(mx[i]==-1) que[++tail]=i; for(i=0;i<=m+n;i++) dist[i]=0; int flag=0; while(head<=tail) { int u=que[head++]... 阅读全文
posted @ 2011-09-02 11:18 Because Of You 阅读(1052) 评论(0) 推荐(0)
摘要:How Many Answers Are WrongTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 521Accepted Submission(s): 213Problem DescriptionTT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the follow 阅读全文
posted @ 2011-09-01 16:21 Because Of You 阅读(582) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#define min(a,b)(a<b?a:b)#define INF 9999999#define MAX 1005int S,N,end,M;int cap[MAX][MAX],flow[MAX],p[MAX];int room[MAX],belong[MAX];int q[10000];int bfs(){ int u,i; for(i=0;i<MAX;i++) { flow[i]=INF; p[i]=-1; } p[S]=0; in... 阅读全文
posted @ 2011-09-01 12:27 Because Of You 阅读(197) 评论(0) 推荐(0)