3 solutions
-
1
#include <bits/stdc++.h> using namespace std; const int N =1e3; int main(){ int n,m; cin>>n>>m; vector<vector<int>> a(N, vector<int>(0)); while(m--){ int x,y; cin>>x>>y; a[x-1].push_back(y);//也是从0开始的 } for(int i = 0 ; i < n ; i++){ sort(a[i].begin(),a[i].end()); } for(int i = 0 ; i < n ; i++){ cout<<a[i].size()<<" "; for(int j = 0 ; j < a[i].size(); j++){ cout<<a[i][j]<<" "; } cout<<endl; } return 0; }
-
1
#include <bits/stdc++.h> using namespace std; struct loc{ vector<int> num; }; int main(){ int n,m,x,y; cin>>n>>m; loc a[n]; for(int i = 0 ; i < m ; i++){ cin>>x>>y; a[x-1].num.push_back(y); } for(int i = 0 ; i < n ; i++){ sort(a[i].num.begin(),a[i].num.end()); } for(int i = 0 ; i < n ; i++){ int size = a[i].num.size(); cout<<size<<" "; for(int j = 0 ; j < size; j++){ cout<<(a[i].num)[j]<<" "; } cout<<endl; } return 0; }
-
-1
#include
#include
#include
#include
#include
#include
#include
typedeflonglongll;
using****namespacestd;
voidsolve14(){
** **map<ll,vector> s;
** **ll n,m;
** **s[0].push_back(0);
** **cin>>n>>m;
** **for (ll i=0; i<m; i++) {
** **ll j,l;
** **cin>>j>>l;
** **s[j].push_back(l);
** **}
** **for (ll i=1; i<=n; i++) {
** **cout<<s[i].size()<<" ";
** **sort(s[i].begin(),s[i].end());
** **for (ll j=0;j<s[i].size() ; j++) {
** **cout<<s[i][j]<<" ";
** **}
** **cout<<endl;
** **}
}
int main(){
** **int t=1;
** **//cin>>t;
** **while(t>0){
** **solve14();
** **t--;
** **}
** **return 0;
}
//用了map
- 1
Information
- ID
- 837
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 2
- Tags
- # Submissions
- 41
- Accepted
- 27
- Uploaded By