怎么说这类问题呢,感觉终属旁门左道,而且有点背离了算法竞赛的初衷。但确实比赛中会有(2019南京区域赛救公主那道题),而且想到时会有豁然开朗的感觉,这也是ACM迷人的地方之一。
况且,ACM本来就不叫算法设计大赛鸭。。。
C. Game with Chips
原题地址
代码:
先把所有点集中到右下角,然后遍历一遍图。
和输入一点毛关系没有你敢信?
一开始读了假题,然后心态一直崩,越做越崩。。。
时隔一年再次div2只A了两题
D. Decreasing Debts
原题地址
代码:
刚看题的时候想了很多算法,网络流、匈牙利。。。
结果看了眼题解。。。题解
#include<iostream>
#include<vector>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 3e5 + 1000;
typedef long long ll;
ll v[N];
vector<int> in, out, ans1, ans2;
vector<ll> ans3;
int n, m;
int main()
{
scanf("%d %d", &n, &m);
while (m--)
{
int x, y; ll z;
cin >> x >> y >> z;
v[x] += z; //支出
v[y] -= z;//收入
}
for (int i = 1; i <= n; i++)
{
if (v[i] > 0) out.push_back(i); //支出
if (v[i] < 0) in.push_back(i);//收入
}
int i = 0, j = 0;
while (1)
{
if (i == out.size() && j == in.size()) break;
ll value = min(v[out[i]], -v[in[j]]);
ans1.push_back(out[i]);
ans2.push_back(in[j]);
ans3.push_back(value);
v[out[i]] -= value;
v[in[j]] += value;
if (v[out[i]] == 0) i++; //换到下一个人匹配
if (v[in[j]] == 0) j++;
}
cout << ans1.size() << endl;
for (int i = 0; i < ans1.size(); i++)
{
cout << ans1[i] << " " << ans2[i] << " " << ans3[i] << endl;
}
return 0;
}
D Complete Tripartite
总感觉怪怪的