My Submissions Accepted:
#include<iostream> #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<utility> #include<map> #include<list> #include<queue> #include<stack> #include<cstring> #include<string> #include<cmath> using namespace std; vector<int> V; map<int,int> M; set<int> S; struct node { int x,y,pos; node(){} node(int x,int y,int pos):x(x),y(y),pos(pos){} }; bool operator < (const node &n1, const node &n2) { return ((n1.x != n2.x) ? n1.x < n2.x : n1.y < n2.y); } node no[100005]; int res = -1; int N; int main() { /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ cin >> N; int x,y; for(int i=0;i<N;i++) { scanf("%d %d",&x,&y); no[i] = node(x,y,i); } sort(no,no+N); int tempx = no[0].x; int temp = 1; while(tempx == no[temp].x) temp++; res = no[temp-1].pos+1; int tempy = no[temp-1].y; //cout << "temp="<< temp<<endl; for(int i=temp;i<N;i++) { if(no[i].y > tempy) { res =-1; break; } } cout << res << endl; /* for(int i=0;i<N;i++) { cout << no[i].x << " " << no[i].y << " " << no[i].pos << endl; } */ return 0; }
Hoặc:
#include<iostream>
#include<cstdio>
#define M 100005
#define oo 1000000001
using namespace std;
int N,res = -1,l[M],r[M];
int main()
{
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
cin >> N;
int left = oo, right = 0;
for(int i=0;i<N;i++)
{
scanf("%d %d",&l[i],&r[i]);
if(left > l[i]) left = l[i];
if(right < r[i]) right = r[i];
}
for(int i=0;i<N;i++)
if(left == l[i] && right == r[i])
{
res = i + 1;
break;
}
cout << res << endl;
return 0;
}
Không có nhận xét nào:
Đăng nhận xét