http://hihocoder.com/contest/msbop2015round2b/problem/3
这个后来一下子忘了格式也没提交上吧。不过就算提交上了过得了小数据,也过不了大数据。这样子存太浪费内存了,那个矩阵很多都没用到。好像看到通过的人的代码量都略长一点。
#include<iostream>
#include<vector>
using namespace std;
int main(){
int N, M, Q, T;
cin >> T >> N >> M >> Q;
for (int i = 0; i < T; i++){
vector<int> ans;
//sex
vector<int> sex(N);
for (int j = 0; j < N; j++){
cin >> sex[j];
}
//relation
vector<int> init(N , 0);
vector<vector<int> > rel(N,init);
for (int k = 0; k < M; k++){
int x, y, z;
cin >> x >> y >> z;
rel[x-1][y-1] = z;
}
for (int l = 0; l < Q; l++){
int query;
cin >> query;
switch (query){
case 1:
int ind;
cin >> ind;
sex[ind-1] = 1 - sex[ind-1];
break;
case 2:
int ina, inb, qin;
cin >> ina >> inb >> qin;
rel[ina-1][inb-1] = qin;
break;
case 3:
int sum = 0;
for (int a = 0; a < rel.size(); a++)
for (int b = 0; b < rel.size(); b++)
{
if (sex[a] != sex[b])
sum += rel[a][b];
}
ans.push_back(sum);
break;
}
}
cout << "Case #" << i+1<< ":" << endl;
for (int res = 0; res < ans.size(); res++){
cout << ans[res] << endl;
}
}
}