上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 26 下一页
摘要: A:Pythagoras'sRevenge代码: 1 #include 2 #define ll long long 3 using namespace std; 4 int main() 5 { 6 ll a; 7 while(scanf("%lld",&a)!=EOF) 8 { 9 if (a==0) break;10 ll aa=a*a;11 int ans=0;12 for(ll i=1;ia) ans++;19 }20 printf("%d\n",ans);21 ... 阅读全文
posted @ 2013-10-27 17:01 Yours1103 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 逆序对数的应用;逆序对数的写法有,二分,树状数组,分治;学习一下;树状数组版:代码: 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 阅读(350) 评论(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 阅读(154) 评论(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 阅读(268) 评论(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 阅读(170) 评论(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 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变;另外,又可以把蚂蚁看成运动方向不变;代码: 1 #include 2 #include 3 using namespace std; 4 #define maxn 10005 5 6 char dir[][10]={"L","Turning","R"}; 7 8 int order[maxn]; 9 10 struct ant11 {12 int id,p,d;13 bool operatorl)puts("Fell off");46 else printf( 阅读全文
posted @ 2013-10-25 23:47 Yours1103 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 这个题的方法很巧妙,首先将整个圆分成(m+n)份,这样移动后的点都是在整数值上;所以只要计算在这样的分法下原来的坐标就行了;代码: 1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int m,n; 8 { 9 while(scanf("%d%d",&n,&m)!=EOF)10 {11 double ans=0;12 for(int i=1;i<n;i++)13 {14 ... 阅读全文
posted @ 2013-10-25 22:49 Yours1103 阅读(161) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 26 下一页