uoj#283. 直径拆除鸡(构造)

传送门

好神的构造题

vfk巨巨的题解

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x,R char ch){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]=ch;
}
int n,m,now,tot,las,res,ans;
int main(){
//  freopen("testdata.in","r",stdin);
    n=read(),m=read();
    for(R int i=1;(i+1)*(i+1)<=n;++i){
        now=0,tot=n;
        fd(j,i,1)now+=tot,tot-=2*j+1;
        now+=tot;if(now>ans)ans=now,res=i;
    }tot=las=0;
    fd(i,res,1){
        fp(j,1,(i<<1))printf("%d %d\n",tot+j,tot+j+1);
        if(tot)printf("%d %d\n",las,tot+i+1);
        las=tot+i+1,tot+=(i<<1)+1;
    }if(!res)las=tot=1;
    while(tot<n)printf("%d %d\n",las,++tot);
    return 0;
}

转载于:https://www.cnblogs.com/bztMinamoto/p/10242423.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值