1 条题解

  • 0
    @ 2026-4-23 19:07:17
    #include<bits/stdc++.h>
    using namespace std;
    const int N=20;
    int hb(int x)
    {
    	int ans=0;
    	while(x>=(1<<(ans)))ans++;
    	return ans;
    }
    struct node{int x,y,c;};
    signed main()
    {
    	int n,pos=0;cin>>n;n--;
    	int x=hb(n+1);vector<node>ans;
    	for(int i=1;i<x;i++)
    		ans.push_back({i,i+1,(1<<(i-1))}),
    		ans.push_back({i,i+1,0});
    	pos=(1<<x-1)-1;
    	while(pos<n)
    	{
    		int y=hb(n-pos);
    		ans.push_back({y,x,pos+1});
    		pos+=(1<<y-1);
    	}
    	cout<<x<<' '<<ans.size()<<'\n';
    	for(auto i:ans)cout<<i.x<<' '<<i.y<<' '<<i.c<<'\n';
    	return 0;
    }
    • 1

    [ABC108D] All Your Paths are Different Lengths

    信息

    ID
    9354
    时间
    2000ms
    内存
    1024MiB
    难度
    10
    标签
    递交数
    7
    已通过
    2
    上传者