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 3 1005 RXD and dividing
题目链接 Problem Description RXD has a tree T, with the size of n. Each edge has a cost. Define f(S) as ...
- 爬虫--PyQuery
什么是PyQuery? PyQuery 初始化 字符串初始化 from pyquery import PyQuery as pq html=""" <div> ...
- MySQL join 用法
select column1, column2 from TABLE1 join TABLE2 on 条件 # select * from table1 join table2; #两个表合成一个se ...
- Three.js基础探寻五——正二十面体、圆环面等
除了立方体.平面.球体,Three.js还提供了很多其他几何形状. 1.圆形 CircleGeometry可以创建圆形或者扇形: THREE.CircleGeometry(radius, segmen ...
- PIP安装时报The repository located at pypi.douban.com is not a trusted or secure host and is being ignore
C:\WINDOWS\system32>pip install scrapyCollecting scrapy The repository located at pypi.douban.com ...
- [Leetcode] Longest Palindromic Subsequence
Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...
- 百度地图js lite api 支持点聚合
百度地图lite api 是专门为h5 绘制海量点设计的,但是偏偏忽略掉了点聚合的需求,所以需要自己动手,做一次二次改造. 我们知道点聚合需要引入开源库: MarkerClusterer: http ...
- juery中监听input的变化事件
$('#searchValue').bind('input propertychange', function() { searchFundList(); });
- Ubuntu 10.04 分辨率调整
最近学长们看了我的本本都在问我,显卡驱动是不是出现什么问题了···分辨率这么差.当时我的分辨率是1024X768,于是我就想修改我的屏幕分辨率改成1280X800.本来很简单的事情,我做起来却非常的曲 ...
- python ORM - sqlalchemy 操作使用
python操作数据库 使用 ORM - sqlalchemy,pymsql 安装: pip install pymsq pip install sqlalchemy 一. '''连接数据库''' ...