atcoderAll Your Paths are Different Lengths[arc102D](乱搞)
Posted quzhizhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了atcoderAll Your Paths are Different Lengths[arc102D](乱搞)相关的知识,希望对你有一定的参考价值。
题目传送门:https://arc102.contest.atcoder.jp/tasks/arc102_b
这道题有点毒瘤啊,罚时上天。。
显然若$ l=2^n $那么就可以直接二进制拆分,但是如果不满足这个要求就有点难办了。。。
但是我们可以按照数位dp的那个树形结构一样,把整个区间$ [0,l) $拆成多个满足二进制拆分的结构(在树上则表现为满二叉树),然后在树根对应的位置额外连边补足权值就行了。(数位dp不懂的可以在这里看:初探数位dp - QuartZ_Z - 博客园,其他细节可以看代码,这题我因为细节wa3。。。)
代码:
#include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<ctime> #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<map> #define ll long long #define ull unsigned long long #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define lowbit(x) (x& -x) #define mod 1000000007 #define inf 0x3f3f3f3f #define eps 1e-18 #define maxn 100010 inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<‘0‘||‘9‘<c;c=getchar())if(c==‘-‘)f=-1; for(;‘0‘<=c&&c<=‘9‘;c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-‘0‘; return tmp*f;} inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;} using namespace std; int x[110],y[110],d[110]; int a[30],base[30]; int n,m,l; int main() { l=read(); if(l<=2){//特判是因为若l<=2,下面建图是时图只有一个点,无法连边 printf("2 %d ",l); for(int i=0;i<l;i++) printf("1 2 %d ",i); return 0; } int len=0; while(1<<len<=l)++len; n=len; m=0; for(int i=0;i<len-1;i++){//二进制拆分 x[++m]=i+1; y[m]=i+2; d[m]=0; x[++m]=i+1; y[m]=i+2; d[m]=1<<i; } for(int i=len-2;i>=0;i--) if(l&(1<<i)){//其实和数位dp一样啦 x[++m]=i+1; y[m]=n; d[m]=l>>(i+1)<<(i+1); } printf("%d %d ",n,m); for(int i=1;i<=m;i++) printf("%d %d %d ",x[i],y[i],d[i]); return 0; }
以上是关于atcoderAll Your Paths are Different Lengths[arc102D](乱搞)的主要内容,如果未能解决你的问题,请参考以下文章
ARC102D All Your Paths are Different Lengths
AtCoder Regular Contest 102 D - All Your Paths are Different Lengths
The following paths are ignored by one of your .gitignore Use -f if you really want to add them.
Where are your from!!!!!!!!!!!! !Baby! {封装}
no permissions (user in plugdev group; are your udev rules wrong?)
[2016-05-24]OMG美语笔记-Witch type of people are not your favorite people?