poj1083 Moving Tables
来源:互联网 发布:videoscribe 软件 编辑:程序博客网 时间:2024/04/29 23:11
水题。。。用来练线段树了。。。
暴力版本。。。。
#include<iostream>#include<string.h>#include<cstdio>using namespace std;int e,t,n,a[40000],x,y,ans,save;int main(){ scanf("%d",&t); for(int i=0;i<t;i++){ for(int j=0;j<40000;j++) a[j]=0; scanf("%d",&n); for(int j=0;j<n;j++){ scanf("%d%d",&x,&y); if(x>y) {e=x;x=y;y=e;} for(int k=(x-1)/2;k<=(y-1)/2;k++){ a[k]++; } } ans=0; for(int j=0;j<40000;j++) if(a[j]>ans) ans=a[j]; cout<<ans*10<<endl; } return 0;}
接下来是线段树版本。。。。。
#include<iostream>#include<cstdio>using namespace std;int e,n,m,l,r,t,x,y;long long ans,save;struct line{ int left,right; int n;}a[3000];void buildt(int l,int r,int step){ a[step].left=l; a[step].right=r; a[step].n=0; if(l==r) return; buildt(l,(l+r)/2,step*2+1); buildt((l+r)/2+1,r,step*2+2);}void insert(int s,int t,int step){ if(s==a[step].left&&t==a[step].right){ a[step].n++;//插入的线段匹配则此条线段的记录+1 return;//插入结束返回 } if(a[step].left==a[step].right) return;//当前线段树的线段无儿子,插入结束返回 int mid=(a[step].left+a[step].right)/2; if(mid>=t) insert(s,t,step*2+1);//如果中点在t的右边,则应该插入到左儿子 else if(mid<s) insert(s,t,step*2+2);//如果中点在s的左边,则应该插入到右儿子 else{//否则,中点一定在s和t之间,把待插线段分成两半分别插到左右儿子里面 insert(s,mid,step*2+1); insert(mid+1,t,step*2+2); }}void search(int x,int step){ if(a[step].left<=x&&a[step].right>=x) save+=a[step].n; if(a[step].left==a[step].right) return; int mid=(a[step].left+a[step].right)/2; if(mid>=x) search(x,step*2+1); else if(mid<x) search(x,step*2+2);}void dfs(int step){ cout<<step<<" "<<a[step].left<<" "<<a[step].right<<" "<<a[step].n<<endl; if(a[step].left==a[step].right) return; dfs(step*2+1); dfs(step*2+2);}int main(){ scanf("%d",&t); for(int i=0;i<t;i++){ buildt(0,200,0); scanf("%d",&n); for(int j=0;j<n;j++){ scanf("%d%d",&x,&y); if(x>y) {e=x;x=y;y=e;} insert((x-1)/2,(y-1)/2,0); } ans=0; for(int j=0;j<200;j++){ save=0; search(j,0); if(save>ans) ans=save; } //dfs(0); cout<<ans*10<<endl; } return 0;}
- POJ1083 Moving Tables
- poj1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083--Moving Tables
- POJ1083 Moving Tables
- poj1083:moving tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables
- poj1083-Moving Tables-贪心
- POJ1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables解题报告
- 【离散化】poj1083 Moving Tables
- POJ1083,Moving Tables,好纠结的题
- launcher定制
- PL/SQL表(oracle内存表)---table()函数用法
- 第七天(Mysql2)
- USACO 1.1 Broken Necklace
- hdu 4011 The 36th ACM/ICPC Asia Regional Shanghai Site —— WarmupWorking in Beijing
- poj1083 Moving Tables
- android 1.6 launcher研究之Drag&Drop模型
- 线程的交互
- 项目需求分析
- 一位资深程序员的忠告(按:用体会更得体、牢骚更恰当!)
- double screenWidth = (double)HtmlPage.Window.Eval("screen.Width");
- 腾讯SOSO面试总结-细节决定成败
- ORACLE多表查询优化
- UBUNTU桌面没图标