1 solutions
-
0
模拟题()
【解题思路】 分别统计每对同学需要分开的行和列,然后找到需要切割的行和列的最大的行和列,按照对应的编号从小到大输出。
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int N=1010; #define x first #define y second int n,m,k,l,d; PII row[N],col[N]; int main() { cin>>n>>m>>k>>l>>d; for(int i=1;i<=n;i++) { row[i].y=i; //行的编号 } for(int i=1;i<=m;i++) { col[i].y=i; //列的编号 } while(d--) { int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; if(x1>x2) swap(x1,x2); if(y1>y2) swap(y1,y2); //保证(x1,y1)<=(x2,y2) if(x1==x2) col[y1].x++; //行相同,用列切割 else row[x1].x++; //列相同用行切割 } sort(row+1,row+n+1); //行从小到大排序 sort(col+1,col+m+1); //列从小到大排序 vector<int> v; for(int i=n;i>n-k;i--) //选出最大的k个 { v.push_back(row[i].y); } sort(v.begin(),v.end()); for(auto x:v) { cout<<x<<" "; } cout<<endl; v.clear(); //清空 for(int i=m;i>m-l;i--) //选出最大的l个 { v.push_back(col[i].y); } sort(v.begin(),v.end()); for(auto x:v) { cout<<x<<" "; } cout<<endl; }
- 1
Information
- ID
- 422
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 9
- Tags
- # Submissions
- 9
- Accepted
- 4
- Uploaded By