E. DoveCCL and Resistance
链接:https://ac.nowcoder.com/acm/contest/33338/D
来源:牛客网

思维+构造
递归处理构造题, dg(n) --->dg(n - k)这样递归处理!
这道题同理,高中物理知识即可。
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define fi first
#define se second
#define pb push_back
#define foa(x, y, z) for(int x = (y), ooo = (z); x <= z; ++x)
#define fos(x, y, z) for(int x = (y), ooo = (z); x >= z; --x)
#define ckmax(x, y) ((x) < (y) ? (x) = (y), 1 : 0)
#define ckmin(x, y) ((x) > (y) ? (x) = (y), 1 : 0)
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
int n, m;
struct node
{
int a, b, w;
};
vector<node> v;
int dg(int st, int x, int y)
{
if(!x) return st;
if(!y) return st + 1;
if(x >= y) {
foa(i, 1, x / y)
v.pb({st + i - 1, st + i, 1});
return dg(st + x / y, x % y, y);
}else {
int t = dg(st, x, y % x);
foa(i, 1, y / x)
v.pb({st, t, 1});
// v.pb({st, st + 2, 0});
// v.pb({t, st + 1, 0});
return t;
}
}
void solve()
{
cin >> n >> m;
int t = dg(1, n, m);
set<int> s;
for(auto &x : v) s.insert(x.a), s.insert(x.b);
cout << s.size() << " " << v.size() << endl;
for(auto &x : v) cout << x.a << " " << x.b << " " << x.w << endl;
cout << "1 " << t << endl;
}
signed main()
{
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
solve();
return 0;
}

浙公网安备 33010602011771号