摘要: 逆序对数的应用;逆序对数的写法有,二分,树状数组,分治;学习一下;树状数组版:代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=100010; 6 int a[maxn],b[maxn],c[maxn]; 7 int n; 8 struct point 9 {10 int num,index;11 bool operator0)35 {36 ans+=c[x];37 x-=lowbit(x);38 }39 return an... 阅读全文
posted @ 2013-10-26 20:58 Yours1103 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 题目要求每次输出中间的那个数,如果数据很大肯定扛不住;所以用两个优先队列来维护;这样的话中间的那个数反正会在两个队列的任何一个的头部;时间复杂度肯定比较小;代码: 1 #include 2 #include 3 using namespace std; 4 int l1,l2; 5 priority_queue q1; 6 priority_queue, greater > q2; 7 void add(int x) 8 { 9 q2.push(x);10 l2++;11 if(!q1.empty() && !q2.empty())12 {13 ... 阅读全文
posted @ 2013-10-26 19:53 Yours1103 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 湖南大学的oj上有这套比赛;这题是个简单的计算几何,首先去掉重复的边,然后判断是否全部平行;代码: 1 #include 2 #define maxn 105 3 using namespace std; 4 5 struct node 6 { 7 int x1,y1; 8 int x2,y2; 9 } no[maxn];10 11 bool cross(node a,node b)12 {13 int x=(b.x1-a.x1)*(a.y2-a.y1)-(b.y1-a.y1)*(a.x2-a.x1);14 int y=(b.x2-a.x1)*(a.y2-... 阅读全文
posted @ 2013-10-26 19:27 Yours1103 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 一个简单的线段树;被我看错题了,浪费一个半小时; 1 #include 2 #define maxn 500005 3 using namespace std; 4 5 struct tree 6 { 7 int l,r,value; 8 tree *right,*left; 9 }tr[maxn];10 int nonocount;11 int ans;12 13 void build(tree *rt,int l,int r)14 {15 rt->l=l;16 rt->r=r;17 if(l==r)18 {19 scanf(... 阅读全文
posted @ 2013-10-26 17:53 Yours1103 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 字典树,可惜比赛的时候有两句话写倒了;害得我调了一个小时;今天不宜做题 = =代码: 1 #include 2 #include 3 #define maxn 2600009 4 using namespace std; 5 6 struct node 7 { 8 bool flag; 9 int cnt;10 node *a[26];11 } no[maxn];12 13 char s[100];14 int ans,nonocount;15 node *newnode()16 {17 node *p=no+nonocount++;18 p->fla... 阅读全文
posted @ 2013-10-26 17:50 Yours1103 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 简单题,二分就行; 1 #include 2 #include 3 #define pi acos(-1.0) 4 #define eps 0.000001 5 #define maxn 10009 6 using namespace std; 7 double area[maxn]; 8 9 int main()10 {11 int t,n,f,ri;12 double r=-1;13 scanf("%d",&t);14 while(t--)15 {16 scanf("%d%d",&n,&f);17 f=f+1;18 ... 阅读全文
posted @ 2013-10-26 10:57 Yours1103 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 代码: 1 #include 2 using namespace std; 3 4 int getans(int x) 5 { 6 int ans=1; 7 while(x>1) 8 { 9 x>>=1;10 ans++;11 }12 return ans;13 }14 15 int main()16 {17 int n;18 while(scanf("%d",&n)!=EOF)19 printf("%d\n",getans(n));20 return 0;21 }View Cod... 阅读全文
posted @ 2013-10-26 10:31 Yours1103 阅读(101) 评论(0) 推荐(0) 编辑