ZOJ Problem Set - 2319 Beautiful People
2017-04-20 08:46
337 查看
Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge
The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi. Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si <= Sj and Bi >= Bj or if Si >= Sj and Bi <= Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn��t even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much).
To celebrate a new 2005 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club prestige at the apropriate level, administration wants to invite as many people as possible.
Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains integer N - the number of members of the club. (2 <= N <= 100 000). Next N lines contain two numbers each - Si and Bi respectively (1 <= Si, Bi <= 109).
Output
On the first line of the output file print the maximum number of the people that can be invited to the party. On the second line output N integers - numbers of members to be invited in arbitrary order. If several solutions exist, output any one.
Sample Input
1
4
1 1
1 2
2 1
2 2
Sample Output
2
1 4
这题其实就是求最长上升子序列的,并记录路径O(n^2)度写过,O(nlogn)第一次写,,其实都是一样的,先按s递增,b递减,排序然后就是求最长上升子序列了
The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi. Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si <= Sj and Bi >= Bj or if Si >= Sj and Bi <= Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn��t even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much).
To celebrate a new 2005 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club prestige at the apropriate level, administration wants to invite as many people as possible.
Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains integer N - the number of members of the club. (2 <= N <= 100 000). Next N lines contain two numbers each - Si and Bi respectively (1 <= Si, Bi <= 109).
Output
On the first line of the output file print the maximum number of the people that can be invited to the party. On the second line output N integers - numbers of members to be invited in arbitrary order. If several solutions exist, output any one.
Sample Input
1
4
1 1
1 2
2 1
2 2
Sample Output
2
1 4
这题其实就是求最长上升子序列的,并记录路径O(n^2)度写过,O(nlogn)第一次写,,其实都是一样的,先按s递增,b递减,排序然后就是求最长上升子序列了
#include<cstdio> #include<cstring> #include<stdlib.h> #include<fstream> #include<ctype.h> #include<math.h> #include<stack> #include<queue> #include<map> #include<set> #include<vector> #include<string> #include<iostream> #include<algorithm> #include<utility> #include<iomanip> #include<time.h> #include<iostream> #define lowbit(x) (x&-x) #define abs(x) ((x)>0?(x):-(x)) using namespace std; typedef long long ll; const double Pi = acos(-1.0); const int N = 1e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10; const double e=2.718281828459 ; const double esp=1e-9; int t,n; struct node { int x,y,index; } a ; int pre ,dp ,res ; bool cmp(node aa,node bb) { if(aa.x==bb.x) return aa.y>bb.y; return aa.x<bb.x; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); memset(pre,0,sizeof(pre)); memset(res,0,sizeof(res)); memset(dp,0,sizeof(dp)); for(int i=1; i<=n; i++) { scanf("%d%d",&a[i].x,&a[i].y); a[i].index=i; } sort(a+1,a+1+n,cmp); // for(int i=1;i<=n;i++) // printf("%d %d\n",a[i].x,a[i].y); int len=1; pre[1]=1 ,dp[1]=1 ; for(int i=2;i<=n;i++) { if(a[i].y>a[dp[len]].y) { dp[++len]=i, pre[i]=dp[len-1]; } else { int L=1, R=len, mid; while(L<=R) { mid=(L+R)>>1; if(a[dp[mid]].y<a[i].y) L=mid+1; else R=mid-1; } dp[L]=i; pre[i]=dp[L-1]; } } printf("%d\n",len); int k=len,i=dp[len]; while(len) { res[len]=a[i].index; i=pre[i]; len--; } for(int i=1;i<=k;i++) { if(i!=k) printf("%d ",res[i]); else printf("%d\n",res[i]); } if(t) puts(""); } }
相关文章推荐
- ZOJ Problem Set - 2319 Beautiful People || sgu 199
- ZOJ Problem Set - 1002 Fire Net
- ZOJ Problem Set - 3418 Binary Number
- ZOJ Problem Set–2417 Lowest Bit
- ZOJ Problem Set - 3490 String Successor(字符串模拟)
- ZOJ Problem Set - 2100
- ZOJ Problem Set–1879 Jolly Jumpers
- ZOJ Problem Set–2405 Specialized Four-Digit Numbers
- ZOJ Problem Set - 1003Crashing Balloon
- ZOJ Problem Set - 1109 Language of FatMouse
- ZOJ Problem Set - 3782 python
- ZOJ Problem Set - 1251 Box of Bricks
- ZOJ Problem Set - 1037 Gridland
- ZOJ Problem Set - 3758 素数
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 1049||I Think I Need a Houseboat
- ZOJ Problem Set - 1338 Up and Down Sequences 解释 ac代码
- ZOJ Problem Set - 2818 Root of the Problem
- ZOJ Problem Set - 2679 Old Bill
- ZOJ Problem Set - 1078 Palindrom Numbers