9 条题解
-
48
锯齿矩阵求解
#include <bits/stdc++.h> using namespace std; vector<int> v[10005]; int n,m; int x,y; int main(){ cin >> n >> m; for (int i = 1;i <= m;i ++){ cin >> x >> y; v[x].push_back(y); } for (int i = 1;i <= n;i ++){ for (int j = 0;j < v[i].size();j ++){ cout << v[i][j] << " "; } cout << endl; } return 0; }
AC代码,点个赞再走呗~
-
14
过辣!
↓↓↓这还不够详细?!↓↓↓
#include <iostream> #include <algorithm> #include <cmath> #include <vector> using namespace std; typedef long unsigned int k;//为啥用这个,因为不想听编译提示狗叫 int n , m , x , y; int main() { cin >> n >> m; vector<int> v[n+5]; for (int i = 1; i <= m ; i++) { cin >> x >> y; v[x].push_back(y); } for (int i = 1 ; i <= n ; i++) { for (k j = 0 ; j < v[i].size() ; j++) { cout << v[i][j] << " "; } cout << endl; } return 0; }
一份AC代码只需要一个赞了啊!
-
14
#include <bits/stdc++.h> using namespace std; int x, y; vector<int> a[100000]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x >> y; a[x].push_back(y); } for (int i = 1; i <= n; i++) { for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << " "; cout << endl; } return 0; }
-
9
精品题解
FROM:丁丁
题目大意
存在一个每行不等长的矩阵,矩阵共有n行,存在m个操作,每个操作包括x和y,表示在第x行末尾插入一个元素y。
解析
建立一个vector数组v[10005],当前操作为{x, y},就将v[x].push_back(y),最后输出即可。
关键代码
- 定义部分:
int x, y; vector<int> a[100000]; ```
- 主程序:
for (int i = 0; i < m; i++) { cin >> x >> y; a[x].push_back(y); } for (int i = 1; i <= n; i++) { for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << " "; cout << endl; }
想对你说
- 好好自己做 不要什么都抄 会一无所获的~
- 加油!!
-
6
精品题解
FROM:丁丁
题目大意
存在一个每行不等长的矩阵,矩阵共有n行,存在m个操作,每个操作包括x和y,表示在第x行末尾插入一个元素y。
建立一个vector数组v[10005],当前操作为{x, y},就将v[x].push_back(y),最后输出即可。关键代码
定义部分:
int x, y; vector<int> a[100000];
主程序:
for (int i = 0; i < m; i++) { cin >> x >> y; a[x].push_back(y); } for (int i = 1; i <= n; i++) { for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << " "; cout << endl; }
想对你说
- 好好自己做 不要什么都抄 会一无所获的~
- 加油!!
-
3
#include <bits/stdc++.h> #define ll long long using namespace std; void start(); const int N=2; vector<int> a[10005]; int main(){ start(); int n,m,x,y; cin>>n>>m; while(m--){ cin>>x>>y; a[x].push_back(y); } for(int i=1;i<=n;i++){ for(int j:a[i]) cout<<j<<' '; cout<<'\n'; } return 0; } void start(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); }
-
3
题目大意
存在一个每行不等长的矩阵,矩阵共有n行,存在m个操作,每个操作包括x和y,表示在第x行末尾插入一个元素y。
完整思路
建立一个vector数组v[10005],当前操作为{x, y},就将v[x].push_back(y),最后输出即可。
题解
vector<int> v[10005]; // 保存 for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; v[x].push_back(y); } // 输出 for (int i = 1; i <= n; i++) { for (int j = 0; j < v[i].size(); j++) { cout << v[i][j] << " "; } cout << endl; }
-
2
#include <iostream> using namespace std; vector<int> v[10005]; int n,m; int x,y; int main(){ cin >> n >> m; for (int i = 1;i <= m;i ++){ cin >> x >> y; v[x].push_back(y); } for (int i = 1;i <= n;i ++){ for (int j = 0;j < v[i].size();j ++){ cout << v[i][j] << " "; } cout << endl; } return 0; }
已AC代码,点个赞呗!
- 1
信息
- ID
- 252
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- (无)
- 递交数
- 671
- 已通过
- 470
- 上传者