标签:
Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define mem(x,y) memset(x,y,sizeof(x)) 7 using namespace std; 8 typedef long long LL; 9 const int INF=0x3f3f3f3f; 10 int a[1100],b[1100]; 11 char s[5]; 12 int getnum(){ 13 int x=0; 14 if(s[0]==‘A‘)x=14; 15 else if(s[0]==‘T‘)x=10; 16 else if(s[0]==‘J‘)x=11; 17 else if(s[0]==‘Q‘)x=12; 18 else if(s[0]==‘K‘)x=13; 19 else if(s[0]>=‘2‘&&s[0]<=‘9‘)x=s[0]-‘0‘; 20 x=x*5; 21 if(s[1]==‘C‘)x+=1; 22 else if(s[1]==‘D‘)x+=2; 23 else if(s[1]==‘S‘)x+=3; 24 else if(s[1]==‘H‘)x+=4; 25 return x; 26 } 27 int main(){ 28 int T,N; 29 scanf("%d",&T); 30 while(T--){ 31 scanf("%d",&N); 32 for(int i=0;i<N;i++){ 33 scanf("%s",s); 34 a[i]=getnum(); 35 } 36 for(int i=0;i<N;i++){ 37 scanf("%s",s); 38 b[i]=getnum(); 39 } 40 // for(int i=0;i<N;i++)printf("%d ",a[i]);puts(""); 41 // for(int i=0;i<N;i++)printf("%d ",b[i]);puts(""); 42 sort(a,a+N);sort(b,b+N); 43 int ans=0; 44 for(int i=0,j=0;i<N&&j<N;){ 45 if(b[i]>=a[j]){ 46 i++;j++;ans++; 47 } 48 else i++; 49 } 50 printf("%d\n",ans); 51 } 52 return 0; 53 }
Description
Your task is counting the segments of different colors you can see at last.
Input
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
If some color can‘t be seen, you shouldn‘t print it.
Print a blank line after every dataset.
Sample Input
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
题解:暴力;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define mem(x,y) memset(x,y,sizeof(x)) using namespace std; typedef long long LL; const int INF=0x3f3f3f3f; const int MAXN=1e6+10; int tree[MAXN],pre[MAXN]; int main(){ int N,x,y,z; while(~scanf("%d",&N)){ mem(tree,-1);mem(pre,0); for(int i=0;i<N;i++){ scanf("%d%d%d",&x,&y,&z); for(int j=x;j<y;j++)tree[j]=z; } for(int i=0;i<=8000;i++){ if(tree[i]==-1)continue; pre[tree[i]]++; while(tree[i+1]==tree[i])i++; } for(int i=0;i<=8000;i++){ if(!pre[i])continue; printf("%d %d\n",i,pre[i]); } puts(""); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4946257.html