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处 ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 6 1003 HDU 6098 Inversion (模拟)
题目链接 Problem Description Give an array A, the index starts from 1. Now we want to know Bi=maxi∤jAj , ...
- 学习webpack
前言 webpack前端工程中扮演的角色越来越重要,它也是前端工程化很重要的一环.本文将和大家一起按照项目流程学习使用wbepack,妈妈再也不用担心我不会使用webpack,哪里不会看哪里.这是一个 ...
- 设计模式之Composite
设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) Composite定义? 将对象以树形结构组织起来,以达成“部分-整体” 的层次结构. 想到Compo ...
- Java Spring boot 企业微信点餐系统
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- 转:字符集和字符编码(Charset & Encoding)
转自:http://www.cnblogs.com/skynet/archive/2011/05/03/2035105.html ——每个软件开发人员应该无条件掌握的知识! ——Unicode伟大的创 ...
- Linux系统调优及安全设置
1.关闭SELinux #临时关闭 setenforce 0 #永久关闭 vim /etc/selinux/config SELINUX=disabled 2.设定运行级别为3 #设定运行级别 vim ...
- MySQL 操作总结
1. 数据库级别操作 1.1 创建数据库 CREATE DATABASE db1 default charset utf8 collate utf8_general_ci; 1.2 删除数据库 DRO ...
- SuSE Linux Supervisor的安装与使用案例
建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 ...
- Tutorial: Reverse debugging with GDB 7 (转载)
Tutorial: Reverse debugging with GDB 7 Tutorial: Reverse debugging with GDB 7 by Jay Conrod posted o ...
- Nginx 虚拟目录和虚拟主机的配置
nginx.conf 配置文件的几个常用命令 nginx 配置文件主要分为六个区域: main: 全局设置 events: nginx工作模式 http: http设置 sever: 主机设置 loc ...