E. Turn Off The TV Educational Codeforces Round 29
Posted cmyg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E. Turn Off The TV Educational Codeforces Round 29相关的知识,希望对你有一定的参考价值。
http://codeforces.com/contest/863/problem/E
注意细节
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define E 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=2e5+10; 25 26 struct node 27 { 28 int x,y,z; 29 }f[maxn]; 30 31 bool vis[maxn]={0}; 32 33 int cmp(node a,node b) 34 { 35 if (a.x==b.x) 36 return a.y>b.y; 37 else 38 return a.x<b.x; 39 } 40 41 int main() 42 { 43 int n,i,j,yy; 44 scanf("%d",&n); 45 for (i=1;i<=n;i++) 46 scanf("%d%d",&f[i].x,&f[i].y),f[i].z=i; 47 sort(f+1,f+n+1,cmp); 48 vis[f[1].z]=1; 49 j=1; 50 for (i=1;i<=n;) 51 { 52 yy=f[j].y+1; 53 i++; 54 j=i; 55 while (i<=n && f[i].x<=yy) 56 { 57 if (f[i].y>f[j].y) 58 j=i; 59 i++; 60 } 61 if (f[j].y<=yy-1) 62 j=i; 63 else 64 i--; 65 vis[f[j].z]=1; 66 } 67 for (i=1;i<=n;i++) 68 if (!vis[i]) 69 { 70 printf("%d",i); 71 return 0; 72 } 73 printf("-1"); 74 return 0; 75 } 76 /* 77 3 78 79 3687 7959 80 81 4918 9822 82 83 8049 11728 84 */
以上是关于E. Turn Off The TV Educational Codeforces Round 29的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 863E Turn Off The TV 思维,扫描线