随笔分类 -  hdu

摘要:一道比较简单但是繁琐的三维计算几何,找错误找的我好心酸,没想到就把一个变量给写错了 = =;题目的意思是求平面切长方体的截面面积+正方体顶部所遮盖的面积;找出所有的切点,然后二维凸包一下直接算面积即可!发个代码纪念一下!代码: 1 #include 2 #include 3 #include 4 #include 5 #define eps 1e-8 6 using namespace std; 7 8 inline int sig(double x){return (x>eps)-(x=-eps&&t1&&cross2(ch[m-1]-ch[m-2],p 阅读全文
posted @ 2013-10-02 10:49 Yours1103 阅读(274) 评论(0) 推荐(0)
摘要:计算几何的题目,很简单;自己随手敲了个,纪念下! 1 #include 2 #include 3 using namespace std; 4 5 struct point 6 { 7 double x,y; 8 point(double x=0,double y=0):x(x),y(y) { } 9 } a,b,c,d;10 11 point midd(point a,point b)12 {13 return point((a.x+b.x)/2.0,(a.y+b.y)/2.0);14 }15 point operator + (point a,point b)16... 阅读全文
posted @ 2013-10-01 17:52 Yours1103 阅读(185) 评论(0) 推荐(0)
摘要:也是一个数学题;主要用到的是排列组合的知识,推推公式就行了,挺简单的;唯一要注意的是A(0,0)=1;在这个上面WA了几次,= =代码: 1 #include 2 #define ULL unsigned long long 3 #define maxn 21 4 using namespace std; 5 6 ULL C[maxn+5][maxn+5];//范围可向上变更 7 ULL A[maxn]; 8 void builtC(){ 9 memset(C,0,sizeof(C));10 C[0][0]=1;11 for(int i=1;i<=maxn;i++)... 阅读全文
posted @ 2013-10-01 16:29 Yours1103 阅读(202) 评论(0) 推荐(0)
摘要:一个简单的规律题,每一列都是一个等差数列;代码: 1 #include 2 #define ll long long 3 using namespace std; 4 5 int main() 6 { 7 int p; 8 int ca=1; 9 scanf("%d",&p);10 while(p--)11 {12 int a,b;13 scanf("%d",&ca);14 scanf("%d%d",&a,&b);15 ll ans=(a-b)*b+1;16 printf... 阅读全文
posted @ 2013-10-01 16:24 Yours1103 阅读(153) 评论(0) 推荐(0)
摘要:一个组合游戏题。解答: 从后面往前面推,首先n-1是必胜位,然后前面的k位是必败位,如此循环下去。所以题目就容易了!代码: 1 #include 2 using namespace std; 3 int main() 4 { 5 int n,k; 6 while(scanf("%d%d",&n,&k)&&(n+k)) 7 { 8 int x=(n)%(k+1); 9 if(x&1)puts("Tang");10 else puts("Jiang");11 }12 return 0;13 }Vie 阅读全文
posted @ 2013-10-01 16:17 Yours1103 阅读(116) 评论(0) 推荐(0)
摘要:这次的答案是猜出来的,如果做得话应该是应该是一个几何概型的数学题;答案就是:n/(m^(n-1));具体的证明过程: 1.首先枚举这M个点中的的两个端点,概率是:n*(n-1); 2.假设这个蛋糕是个圆盘状的,圆面面积为1,然后为了满足题目的要求,这两个端点+圆心所组成的扇形的的面积应该小于1/m; 3.然后对剩下的所有点都应该分布在这个扇形里面,加设扇形面积为x,则结果应该为:x^(n-2)在0-1/m中的积分,然后再乘以n*n-1;n,m0){12 t-=1;13 BigInteger m = sc.nextBigInteger();1... 阅读全文
posted @ 2013-09-28 21:34 Yours1103 阅读(244) 评论(0) 推荐(0)
摘要:一个KMP的简单题不过好久没用过这个东东了,今天写的时候花了很多时间;只需要花点时间判断下所有的元素都相同的的情况就行了! 1 #include 2 #include 3 #include 4 #define maxn 1000006 5 using namespace std; 6 char s[maxn]; 7 int next[maxn]; 8 9 void getnext(char *t)10 {11 // t为模式串12 int i=0,j= -1,l = strlen(t);13 next[0] = -1;14 while(i < l)15 ... 阅读全文
posted @ 2013-09-28 21:29 Yours1103 阅读(251) 评论(0) 推荐(0)
摘要:一道dp题,虽然知道是dp,但是不会做;学习了ACM_cxlove大神的代码,终于明白了;搬运工:dp[i][j][k]表示 前i个已经完全匹配,而这时候,第i+1个已经加了j位,第i+2位已经加了k转移分为两步,枚举加,枚举减;上面是大神的原话,不过看了好久的代码才明白;下面是我的一点领悟: 1 #include 2 #include 3 #include 4 #define inf 1<<20 5 #define N 1005 6 using namespace std; 7 char s1[N],s2[N]; 8 int dp[N][10][10]; 9 int main() 阅读全文
posted @ 2013-09-25 17:03 Yours1103 阅读(196) 评论(0) 推荐(0)
摘要:一道枚举+搜索题;很容易看出这道题目要求尽量不在大的城市里面建加油站;所以从最大的城市开始枚举!代码: 1 #include 2 #include 3 #include 4 #define maxn 130 5 #include 6 using namespace std; 7 8 struct node 9 {10 double x,y;11 } no[maxn];12 queueq;13 int dis[maxn][maxn],n,d,dd[maxn];14 bool vis[maxn],flag[maxn];15 16 bool bfs()17 {18 while(!q... 阅读全文
posted @ 2013-09-25 15:04 Yours1103 阅读(147) 评论(0) 推荐(0)
摘要:计算几何+数值计算的题目;要用到辛普森积分,没有学过~~~参考学习了 acm_Naruto大神的代码!代码: 1 #include 2 #include 3 #include 4 #define maxn 20005 5 using namespace std; 6 int n,a,b,c,l,r,x[maxn],y[maxn]; 7 double sqr(double x) 8 { 9 return x*x;10 }11 double len(double x)12 {13 double t,tt;14 t=(sqrt((b+2*a*x)*(b+2*a*x)+1)+2... 阅读全文
posted @ 2013-09-24 00:08 Yours1103 阅读(368) 评论(0) 推荐(0)
摘要:参考阳神的博客写的,非常好的一个方法。题目的意思是: 对于每对点 找出他们之间所有路径中 最长边 的最小值~~~好拗口的!思路: 直接找出满足要求的太过于麻烦;所以找出不满足条件的,然后用总的数目(n*(n-1))减去不满足的就行;做法: 因为找的是最长边,所以首先将边和查询都按从小到大排好序。因为满足要满足条件,查询的值要比当前已经访问的边的值要大; 另外,访问了边之后要维护,选用并查集!感觉这个方法很正确,但是不会证明 = =!代码: 1 #include 2 #include 3 #define maxn 10005 4 #define maxm 500005 5 using n... 阅读全文
posted @ 2013-09-23 22:28 Yours1103 阅读(290) 评论(0) 推荐(0)
摘要:题目很简单,不过题意很难看懂。就是给一个标准的大小关系的队列,从原队列中找出最多的匹配子队列,感觉就像一个KMP算法+贪心;不过这个题可能数据有点水把,竟然只要判断相邻的关系就可以A掉;代码: 1 #include 2 #define maxn 100005 3 using namespace std; 4 int q[maxn],st[maxn],n,m,k; 5 6 bool g(int a) 7 { 8 int i; 9 for(i=a; iq[i+1]&&st[i-a]>st[i-a+1]))continue;12 else break;13 ... 阅读全文
posted @ 2013-09-23 16:36 Yours1103 阅读(335) 评论(0) 推荐(1)
摘要:一道很简单的题,不过在比赛的时候没有写出来;刚刚看到这个题,我以为是一个图论题,后来发现其实就是一个暴力的题;用bfs,因为一个人与他不认识的人肯定不会在一个集合,如果判断出现冲突则分配失败,否则就成功;代码: 1 #include 2 #include 3 #include 4 #define maxn 103 5 using namespace std; 6 7 int map[maxn][maxn],n; 8 int b[maxn]; 9 10 bool bfs(int a)11 {12 queueq;13 q.push(a);14 while(!q.empty... 阅读全文
posted @ 2013-09-23 12:52 Yours1103 阅读(366) 评论(0) 推荐(1)
摘要:一道超级easy的贪心一眼看出了他的本质;代码: 1 #define mod 31536000 2 #include 3 #include 4 #include 5 #define maxn 100005 6 using namespace std; 7 8 struct node 9 {10 int a,b;11 double ave;12 bool operator <(const node &t)const13 {14 if(ave==t.ave) return a<t.a;15 return ave<t.ave;16 ... 阅读全文
posted @ 2013-09-18 22:16 Yours1103 阅读(163) 评论(0) 推荐(0)
摘要:今天模拟赛的一个模拟题;每次看到这种题就感觉很繁琐;这次静下心来写写,感觉还不错!就是很多错误,浪费了一点时间;代码: 1 #include 2 #include 3 using namespace std; 4 5 int d[4][2]= {{1,0},{0,1},{-1,0},{0,-1}}; 6 7 struct run 8 { 9 int x,y;10 int s,p,d;11 } r[2];12 int t,n;13 void go()14 {15 bool flag;16 for(int i=0; in)37 {38 ... 阅读全文
posted @ 2013-09-18 22:14 Yours1103 阅读(245) 评论(0) 推荐(0)
摘要:今天模拟了一场去年金华的现场赛;我和小珺两人出了5个题,感觉还可以;不过这次的题目确实比较简单;这个题目感觉不错,不难,以前见过用这种方法的,但一直没写过;这次写下练练手:思路,将角度分成1000份,然后暴力;代码: 1 #include 2 #include 3 #include 4 #define du 0.003141593 5 #define g 9.8 6 #define eps 0.0000001 7 using namespace std; 8 9 int ans,n;10 double dan[205],h,l1,r1,l2,r2;11 12 void go()13 {14 . 阅读全文
posted @ 2013-09-18 22:10 Yours1103 阅读(222) 评论(0) 推荐(0)
摘要:树形dp;思想: 把正向边赋值为0;反向边赋值为1;然后求出点到其他点的最小距离;两次dfs:第一次是从下往上:记录每个点到所有子树中需要改变的边的条数;第二次是自上往下:由父节点求子节点到所有点的需要改变的边的条数。代码: 1 #include 2 #include 3 #include 4 #define maxn 200005 5 using namespace std; 6 7 struct node 8 { 9 int v,w;10 };11 12 vectorve[maxn];13 int dp[maxn],res;14 bool vis[maxn];15 16 void... 阅读全文
posted @ 2013-09-17 17:21 Yours1103 阅读(540) 评论(0) 推荐(0)
摘要:树形dp题,要求求出书上的最远距离;很经典的一种树形dp;思路:最远距离要么是从老爸的最远距离+自己与老爸的距离; 要么是儿子的最远距离+自己与儿子的距离;然后比较上面两个的大小就是答案了!参考了别人的代码:两次搜索:1.第一次搜索是从下至上的搜索,找到每个节点的最远距离f[],次远距离sf[];并记录最远距离的那个点;2.第二次搜索是从上往下的搜索,找到老爸那边来的最远距离dp[];代码: 1 #include 2 #include 3 #include 4 #define maxn 10005 5 using namespace std; 6 7 struct node 8... 阅读全文
posted @ 2013-09-17 16:11 Yours1103 阅读(204) 评论(0) 推荐(0)
摘要:树形dp的基础题;状态转移很简单:老爸没选,儿子可选可不选,最大就行;老爸选了,儿子肯定不能选;dp[root][0]+=max(dp[son][1],dp[son][0]); dp[root][1]+=dp[son][0];代码: 1 #include 2 #include 3 #include 4 #define maxn 6003 5 using namespace std; 6 7 int w[maxn],dp[maxn][2]; 8 vectorve[maxn]; 9 bool vis[maxn];10 11 void dfs(int a)12 {13 vis... 阅读全文
posted @ 2013-09-17 09:09 Yours1103 阅读(203) 评论(0) 推荐(0)
摘要:一个超级超级水的题,不明白当时比赛的时候没有出来;思路很简单,dfs暴力一下就行,枚举每个顶点,题目一共才20个点,就是20^4方的时间复杂度,完全可以承受;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct node 7 { 8 int x,y; 9 } no[22];10 bool use[22];11 int ans,num,n;12 13 void dfs(int i)14 {15 ans=max(num,ans);16 for(; i<n; i++)17 {18... 阅读全文
posted @ 2013-09-16 22:06 Yours1103 阅读(190) 评论(0) 推荐(0)