MT3011
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;int n;
struct NODE{vector<int> v;int ind = 0;
}g[N];int main( )
{cin >> n;int x;for(int i = 1; i <= n; i++){for(int j = 1; j<= n-1; j++){cin >> x;g[i].v.push_back(x);}}int ans = 0;while(true){int flag = 0;int vis[N] = {0};for(int i = 1; i <= n; i++){if (vis[i] || g[i].ind == n - 1){continue;}int j = g[i].v[g[i].ind];if (vis[j] || g[j].ind == n - 1 || g[j].v[g[j].ind] != i) continue;flag = 1;vis[i] = vis[j] = 1;g[i].ind++;g[j].ind++;}if(!flag)break;else {ans++;}}int flag = 0;for(int i = 1; i <= n; i++){if (g[i].ind != n - 1){flag = 1;break;}}if (flag)ans =- 1;cout << ans;return 0;
}
MT3012序列加法
代码
#include<bits/stdc++.h> using namespace std;
const int N = 1e6 + 7;int a[N],n,m,t[N];
int main( )
{ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin >> n >>m;for (int i = 1; i<= n; i++) cin >> a[i];while(m--){int num;cin >> num;if(num == 1){int x,y;cin >> x >> y;t[x] += y;}if(num == 2){int i;cin >> i;int ans = a[i];for(int j = 1; j <= i / j; j ++){if(i % j == 0){if (i % j == 0){if ((j * j) == i) {ans += t[j];}else{ans += t[j] + t[i / j];}}}}cout << ans << endl;}}return 0;
}
MT3013剪纸