本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

本文作者:ljh2000 
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

题目链接:http://uoj.ac/problem/283

正解:枚举+数学

解题报告:

  这道题很神啊,我在考场上想了一下,觉得菊花树很正确,但是想想就会发现菊花树的答案稳定在2*n-1上,并不优秀。

  题解说的很明白了,我们先枚举链的条数,计算出最优值,只需在算出的最优链数上连边即可。

  有一些小trick,需要注意。

  题解:http://vfleaking.blog.uoj.ac/blog/2292

  

//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <complex>
using namespace std;
typedef long long LL;
int n,m,now,tot;
int ans,chain,last;
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
} inline void work(){
n=getint(); m=getint();
for(int i=1;(i+1)*(i+1)<=n;i++) {//枚举链的条数
now=0; tot=n;
for(int j=i;j>=1;j--)
now+=tot,tot-=2*j+1;
now+=tot;
if(now>ans) ans=now,chain=i;
}
tot=0; last=0;
for(int i=chain;i>=1;i--) {//连边
for(int j=1;j<=2*i;j++)
printf("%d %d\n",tot+j,tot+j+1);
if(tot>0) printf("%d %d\n",last,tot+i+1);
last=tot+i+1; tot+=i*2+1;
}
if(chain==0) last=1,tot=1;
while(tot<n) { tot++; printf("%d %d\n",last,tot); }
} int main()
{
work();
return 0;
}

  

UOJ283 直径拆除鸡的更多相关文章

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

    传送门 好神的构造题 vfk巨巨的题解 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) fo ...

  2. UOJ Goodbye Bingshen

    在叶子童鞋的推荐下打了这场比赛... 感觉被虐爆了... 怎么这么多构造题... 我还没写过呢... 交互题是毛线...看了好久没看懂...就放弃了...(我语文好差QAQ...) 最后只会T1... ...

  3. HDU-4679-树的直径(树形dp)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  4. 【CSP模拟赛】避难向导(倍增lca&树的直径)

    耐力OIer,一天7篇博客 题目描述 “特大新闻,特大新闻!全国爆发了一种极其可怕的病毒,已经开始在各个城市 中传播开来!全国陷入了巨大的危机!大量居民陷入恐慌,想要逃到其它城市以 避难!经调查显示, ...

  5. DFS序+线段树 hihoCoder 1381 Little Y's Tree(树的连通块的直径和)

    题目链接 #1381 : Little Y's Tree 时间限制:24000ms 单点时限:4000ms 内存限制:512MB 描述 小Y有一棵n个节点的树,每条边都有正的边权. 小J有q个询问,每 ...

  6. 【bzoj3124】 Sdoi2013—直径

    http://www.lydsy.com/JudgeOnline/problem.php?id=3124 (题目链接) 题意 求树的直径以及直径的交. Solution 我的想法超麻烦,经供参考..思 ...

  7. HFS远程命令执行漏洞入侵抓鸡黑阔服务器

    先来科普一下: HFS是什么? hfs网络文件服务器 2.3是专为个人用户所设计的HTTP档案系统,如果您觉得架设FTP Server太麻烦,那么这个软件可以提供您更方便的网络文件传输系统,下载后无须 ...

  8. poj2631 求树的直径裸题

    题目链接:http://poj.org/problem?id=2631 题意:给出一棵树的两边结点以及权重,就这条路上的最长路. 思路:求实求树的直径. 这里给出树的直径的证明: 主要是利用了反证法: ...

  9. 百钱买百鸡问题 php版本

    /* * 百钱买百鸡问题 * * 我国古代数学家张丘建在<算经>一书中曾提出过著名的“百钱买百鸡”问题,该问题叙述如下:鸡翁一,值钱五:鸡母一,值钱三:鸡雏三,值钱一:百钱买百鸡,则翁.母 ...

随机推荐

  1. Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. Problem H. Hotel in Ves Lagos

    Problem H. Hotel in Ves Lagos Input le: hotel.in Output le: hotel.out Time limit: 1 second Memory li ...

  3. asp.net mvc全局错误处理

    方式一:全局捕获异常 根据错误编码直接跳转到对应静态页面 1,在Global.asax.cs文件中添加错误处理方法Application_Error 代码如下 protected void Appli ...

  4. Delphi里的Windows消息(可查MSDN指定位置)

    各种控件的通知消码和控制消息可由MSDN-> Platform SDK-> User Interface Services->Windows User Interface->C ...

  5. Java的默认构造函数调用

    // 注意,这里不能是 public class OOO,否则编译无法通过,需把文件命名成 OOO.java class OOO { // 注意:如果不定义OOO(),那么Shapes(int i)编 ...

  6. Asp.Net MVC anti-forgery token的问题:nameidentifier not present

    前一篇关于anti-forgery token问题的博文提到我们可以通过修改AntiForgeryConfig.UniqueClaimTypeIdentifier属性来避免AntiForgeryTok ...

  7. python——random模块

    用法示例: import random # 1)随机小数 print(random.random()) # 获取大于0且小于1 之间的小数 random.random() print(random.u ...

  8. Python3.6全栈开发实例[010]

    10.有字符串 "k:1|k1:2|k2:3|k3:4" 处理成字典 {'k':1,'k1':2....} s = "k:1|k1:2|k2:3|k3:4" d ...

  9. SUBMIT RM07DOCS【MB51】 获取返回清单,抓取标准报表数据

    *&---------------------------------------------------------------------* *& Report YT_SUBMIT ...

  10. Some day some time we will do

    Age has been reached the end of the beginning of the world,May be guilty in his seems to passing a l ...