E. DoveCCL and Resistance

链接:https://ac.nowcoder.com/acm/contest/33338/D
来源:牛客网
image

思维+构造

递归处理构造题, 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;
}
posted @   1564269628  阅读(25)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示