CodeForces - 1017C The Phone Number
一开始有一种构造猜想,可以把答案降到 sqrt(N) 级别。
考虑把 {1,2,...,n} 分成 sqrt(N) 段,每一段是连续的sqrt(N)个数。然后我们倒着把每一段数放上。
比如 n=9 的时候就形如 7,8,9 ; 4,5,6 ; 1,2,3.
这样就能保证 LIC和LDC都是 sqrt(N),从而答案就是 2sqrt(N)。
当然这里 sqrt(N) 要取整,但注意一定要向上取整,比如63取sqrt()是7点几,但是如果按7一段分的话会分成9段,不如8一段分分成8段优。
(证明的话把N分成平方数和非平方数讨论一下就可以了)。
虽然不能证明这种方法的正确性,但是暴力跑了下阶乘发现 n<=12 的话都是对的,于是就交了一发,A了、
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005; int n,sz,now;
bool v[N]; int main(){
scanf("%d",&n);
sz=(int)floor(sqrt(n+0.233));
if(sz*sz<n) sz++; now=n,v[n+1]=1; for(int i=1;i<=n;v[now]=1,printf("%d ",now),i++){
now++;
while(v[now]) now-=sz;
if(now<=0) now=1;
} return 0;
}
CodeForces - 1017C The Phone Number的更多相关文章
- dp --- Codeforces 245H :Queries for Number of Palindromes
Queries for Number of Palindromes Problem's Link: http://codeforces.com/problemset/problem/245/H M ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Codeforces 980 E. The Number Games
\(>Codeforces \space 980 E. The Number Games<\) 题目大意 : 有一棵点数为 \(n\) 的数,第 \(i\) 个点的点权是 \(2^i\) ...
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- 【codeforces 805D】Minimum number of steps
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...
- Codeforces C. Split a Number(贪心大数运算)
题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...
- Codeforces 245H Queries for Number of Palindromes
http://codeforces.com/contest/245/problem/H 题意:给定一个字符串,每次给个区间,求区间内有几个回文串(n<=5000) 思路:设定pd[i][j]代表 ...
- codeforces 464C. Substitutes in Number
题目链接 C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 279D The Minimum Number of Variables 状压dp
The Minimum Number of Variables 我们定义dp[ i ][ mask ]表示是否存在 处理完前 i 个a, b中存者 a存在的状态是mask 的情况. 然后用sosdp处 ...
随机推荐
- js和php的时间戳和时间的转化
js时间戳转化为时间 //时间戳转时间 function time(sj) { var now = new Date(sj*1000); var year =now.getFullYear(); va ...
- ES6 中 Array.from() 不能得到的数组元素是 undefined 或是空数组
本文地址:http://www.cnblogs.com/veinyin/p/7944072.html 正确格式 let json = { '0': 'Waaaa~', '1': 'Hello,', ...
- 基于canvas的图片编辑合成器
在我们日常的前端开发中,经常会要给服务器上传图片,但是局限很大,图片只能是已有的,假设我想把多张图片合成一张上传就需要借助图片编辑器了,但是现在我们有了canvas合成就简单多了 首先我们看图片编辑器 ...
- window10_使用技巧
1.系统关机文件 @echo offshutdown -s -t 0 2.终端常用命令 notepad 3.解决浏览器跨域 --disable-web-security --user-data-dir ...
- var_dump打印出来格式太乱 怎么调
var_dump()和print_r() 输出的都是文本格式,在浏览器中就是这样如果你加载了 xdebug 扩展,那么 var_dump() 就会以 html 格式输出
- Ubuntu16.04安装记
Ubuntu16.04安装记 基本信息: 华硕笔记本 Windows 10 家庭版 处理器:Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz 2.71GHz 已安装的内 ...
- Hashtable之Properties
properties的使用:1.Hashtable的实现类,线程安全.与HashMap不同,Hashtable不允许使用null作为key和value2.和HashMap一样,Hashtable也不能 ...
- Python——文件打开模式辨析
版权声明:本文系原创,转载请注明出处及链接. Python中,open()函数打开文件时打开模式如r.r+ .w+.w.a.a+有何不同 r 只能读 r+ 可读可写,不会创建不存在的文件.如果直接写文 ...
- CGI、FastCGI和php-fpm的概念和区别
CGI是HTTP Server和一个独立的进程之间的协议,把HTTP Request的Header设置成进程的环境变量,HTTP Request的正文设置成进程的标准输入,而进程的标准输出就是HTTP ...
- 欧拉回路&欧拉通路判断
欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...