标签:its hdu get price tac important 组合 put microsoft
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 767 Accepted Submission(s): 263
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <climits> 7 #include <cmath> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL ; 15 typedef unsigned long long ULL ; 16 const int maxn = 1e5 + 10 ; 17 const int inf = 0x3f3f3f3f ; 18 const int npos = -1 ; 19 const int mod = 1e9 + 7 ; 20 const int mxx = 100 + 5 ; 21 const double eps = 1e-6 ; 22 const double PI = acos(-1.0) ; 23 24 struct node{ 25 int p, d; 26 }; 27 node h[maxn]; 28 int cmp(const node &l, const node &r){ 29 if(l.p!=r.p) 30 return l.p<r.p; 31 else 32 return l.d<r.d; 33 } 34 int Lower_Bound(int l, int r, int x){ 35 while(l<r){ 36 int m=(l+r)>>1; 37 if(h[m].p>=x) 38 r=m; 39 else 40 l=m+1; 41 } 42 return l; 43 } 44 int n, u, v, fac[30], st[maxn], cnt; 45 int dp[maxn][30], pl, pr, id; 46 int main(){ 47 // freopen("in.txt","r",stdin); 48 // freopen("out.txt","w",stdout); 49 for(int i=0;i<30;i++) 50 fac[i]=(1<<i); 51 while(~scanf("%d",&n)){ 52 for(int i=1;i<=n;i++){ 53 scanf("%d %d",&h[i].p,&h[i].d); 54 dp[i][0]=i; 55 } 56 sort(h+1,h+1+n,cmp); 57 int k=(int)(log((double)n)/log(2.0)); 58 for(int j=1;j<=k;j++) 59 for(int i=1;i+fac[j]-1<=n;i++){ 60 pl=dp[i][j-1]; 61 pr=dp[i+fac[j-1]][j-1]; 62 if(h[pl].d<h[pr].d) 63 dp[i][j]=pl; 64 else 65 dp[i][j]=pr; 66 } 67 u=1; 68 cnt=0; 69 st[cnt++]=1; 70 for(int i=2;i<=n;i++){ 71 v=Lower_Bound(1,i,h[i].p)-1; 72 if(u<=v){ 73 k=(int)(log((double)v)/log(2.0)); 74 pl=dp[u][k]; 75 pr=dp[v-fac[k]+1][k]; 76 if(h[pl].d<h[pr].d) 77 id=pl; 78 else 79 id=pr; 80 if(!(h[id].d<h[i].d)) 81 st[cnt++]=i; 82 }else{ 83 st[cnt++]=i; 84 } 85 } 86 printf("%d\n",cnt); 87 for(int i=0;i<cnt;i++) 88 printf("%d %d\n",h[st[i]].p,h[st[i]].d); 89 } 90 return 0; 91 }
标签:its hdu get price tac important 组合 put microsoft
原文地址:http://www.cnblogs.com/edward108/p/7645722.html