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处 ...
随机推荐
- marquee滚动效果
转载两篇文章: http://blog.sina.com.cn/s/blog_49ce67fc0100atb4.html https://baike.1688.com/doc/view-d359560 ...
- Calendar 日期类介绍
Calendar c = Calendar.getInstance();//创建实例 默认是当前时刻 c.get(Calendar.YEAR); c.get(Calendar.MONTH); c.ge ...
- 微信小程序rpx单位
rpx单位是微信小程序中css的尺寸单位,rpx可以根据屏幕宽度进行自适应.规定屏幕宽为750rpx.如在 iPhone6 上,屏幕宽度为375px,共有750个物理像素,则750rpx = 375p ...
- nginx 配置代理某个路径
location /test{ proxy_pass http://localhost:8765/test; proxy_set_header Host $http_host; } 其中红色的那句可以 ...
- ORACLE ASM中查询表空间使用情况、数据文件路径、裸设备磁盘总大小剩余大小
在ASM中:查询所有磁盘名称.总大小.剩余大小:单位MB-----查看组的信息(总大小)select name,total_mb, free_mb from v$asm_diskgroup; ---查 ...
- Mysql储存过程4:mysql变量设置
默认全局变量是两个@@开头, 可用show variables查看所有默认变量: @@user #declare定义变量只能用在储存过程中 #declare 变量名 数据类型 可选类型 declare ...
- S3C6410 SPI全双工读写流程分析(原创)【转】
转自:http://blog.csdn.net/hustyangju/article/details/21165721 原创博文,知识共享!转载请注明出处:http://blog.csdn.net/h ...
- BZOJ 3958 Mummy Madness
Problem BZOJ Solution 算法:二分+扫描线 快要2019年了,就瞎写一篇博客来凑数,不然感觉太荒凉了-- 答案是可二分的,那么二分的依据是什么呢?不妨设当前二分的答案为\(mid\ ...
- 122.Best Time to Buy and Sell Stock II---dp
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 题目大意:基本定义与121类似,不 ...
- 问题解决:The content of the adapter has changed but ListView did not receive a notification
1. 不要在后台线程中直接调用adapter 2. 不要在后台线程中修改adapter绑定的数据 如果对adapter或者adapter绑定的数据是在线程中,加上runOnUiThread就可以了 r ...