标签:
水题,数组A中是否存在k本书使任意一本书,严格小于数组B中的m本书中的每本书,做一次排序,使A[k-1]<B中第M大的书。存在输出“Yes”,反之“No”
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<ctype.h> 6 #include <map> 7 #include <set> 8 #include <cmath> 9 #include <deque> 10 #include <queue> 11 #include <stack> 12 #include <cstdio> 13 #include <cctype> 14 #include <string> 15 #include <vector> 16 #include <cstdlib> 17 #include <cstring> 18 #include <iostream> 19 #include <algorithm> 20 #define LL long long 21 #define INF 0x7fffffff 22 using namespace std; 23 24 25 int main() 26 { 27 //printf("%10s","hhhh"); 28 //printf("%*s",10,"hhhhhh"); 29 int N1,N2,k,m; 30 int a[100005],b[100005]; 31 int t1=N1-1; 32 int t2=N2-m; 33 cin>>N1>>N2>>k>>m; 34 for(int i=0;i<N1;i++){ 35 cin>>a[i]; 36 } 37 for(int i=0;i<N2;i++){ 38 cin>>b[i]; 39 } 40 if(a[k-1]<b[N2-m]) 41 cout<<"YES"<<endl; 42 else 43 cout<<"NO"<<endl; 44 45 return 0; 46 }
还是水题,但是题意太坑,里面buy和sell是买贵的,卖便宜的,此外,输出的时候,全部按照升序排列。
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<ctype.h> 6 #include <map> 7 #include <set> 8 #include <cmath> 9 #include <deque> 10 #include <queue> 11 #include <stack> 12 #include <cstdio> 13 #include <cctype> 14 #include <string> 15 #include <vector> 16 #include <cstdlib> 17 #include <cstring> 18 #include <iostream> 19 #include <algorithm> 20 #define LL long long 21 #define INF 0x7fffffff 22 using namespace std; 23 24 #define N 1005 25 #define M 100005 26 int pb[N],ps[N],qb[M],qs[M]; 27 int n,s; 28 29 int main() 30 { 31 for(int i=0;i<N;i++){ 32 pb[i]=0; 33 ps[i]=0; 34 } 35 for(int i=0;i<M;i++){ 36 qb[i]=0; 37 qs[i]=0; 38 } 39 cin>>n>>s; 40 char t; 41 int t1=0; 42 int t2=0; 43 int temp,x; 44 for(int i=0;i<n;i++){ 45 getchar(); 46 cin>>t; 47 if(t==‘B‘) 48 { 49 cin>>x>>temp; 50 if(qb[x]==0) 51 { 52 pb[t1]=x; 53 t1++; 54 //cout<<t1<<" "<<t2<<"????"<<endl; 55 } 56 qb[x]+=temp; 57 //else cout<<qb[pb[t1-1]]<<endl; 58 } 59 else if(t==‘S‘){ 60 cin>>x>>temp; 61 if(qs[x]==0) 62 { 63 ps[t2]=x; 64 t2++; 65 // cout<<t1<<" "<<t2<<"????"<<endl; 66 } 67 qs[x]+=temp; 68 //else cout<<qs[ps[t2-1]]<<endl; 69 } 70 // for(int i=0;i<t1;i++){ 71 // cout<<qb[pb[i]]<<endl; 72 // } 73 // for(int i=0;i<t2;i++){ 74 // cout<<qs[ps[i]]<<endl; 75 // } 76 } 77 //cout<<t1<<" "<<t2<<endl; 78 sort(pb,pb+t1); 79 reverse(pb,pb+t1); 80 sort(ps,ps+t2); 81 reverse(ps,ps+t2); 82 for(int j=min(s,t2);j>0;j--){ 83 cout<<"S "<<ps[t2-j]<<" "<<qs[ps[t2-j]]<<endl; 84 //cout<<i<<" "<<t2<<endl; 85 } 86 for(int i=0;i<s&&i<t1;i++){ 87 cout<<"B "<<pb[i]<<" "<<qb[pb[i]]<<endl; 88 //cout<<i<<" "<<t1<<endl; 89 } 90 return 0; 91 }
标签:
原文地址:http://www.cnblogs.com/sunshiniing/p/4761540.html