codeforces div2 603 C. Everyone is a Winner!(二分)
题目链接:https://codeforces.com/contest/1263/problem/C
题意:给你一个数字n,求n/k有多少个不同的数
思路:首先K大于n时,n/k是0。然后k取值在1到n之间的时候进行二分即可求解。
举个例子,比如n = 11,那么k分别取值1 2 3 4 5 6 7 8 9 10 11时候,n/k是 11 5 3 2 2 1 1 1 1 1 1,因为n/k这组数据是具有单调性的,那么我们就可以在n/k这个取值范围内二分查找,每次查找到的不同的取值存起来,最终输出即可
代码:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
int main(){
int t;cin>>t;
while(t--){
ll n;cin>>n;
ll pos = n;
vector<ll> ans;
ans.push_back(0);
ans.push_back(1);
ll cur = n;//表示当前二分区间的右端点
while(cur!=1){
ll l = 1,r = cur;// 1 2 3 4 5 6 7 8 9 10 11
// 11 5 3 2 2 1 1 1 1 1 1
while(l<=r){
ll mid = l + ((r - l) >> 1);
// 1 6
// 4 6
// 5 6
// 6 6
if(n/mid<=ans[ans.size() -1]){
r = mid-1;
}
else if(n/mid>ans[ans.size() -1]){
l = mid+1;
}
}
ans.push_back(n/r);
cur = r;
}
cout<<ans.size()<<endl;
for(int i = 0;i<ans.size() ;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
// 1 2 3 4 5
// 1 2 5
return 0;
}
codeforces div2 603 C. Everyone is a Winner!(二分)的更多相关文章
- codeforces div2 603 D. Secret Passwords(并查集)
题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...
- codeforces div2 603 E. Editor(线段树)
题目链接:https://codeforces.com/contest/1263/problem/E 题意:一个编译器,每次输入一些字符,R表示光标右移,L表示光标左移,然后有一些左括号( 和 右括 ...
- Codeforces Round #603 C. Everyone is a Winner!
题意:给你一个整数n,求所有n/k的值(k∈{1,2,3...,n,.......}). 题解:最简单的方法是用枚举1~sqrt(n),把除数和商放进set中,就能直接水过,但后来看其他人的题解了解到 ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! 二分
C. Everyone is a Winner! On the well-known testing system MathForces, a draw of n rating units is ar ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)
链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...
- Codeforces Round #603 (Div. 2) C.Everyone is A Winner!
tag里有二分,非常的神奇,我用暴力做的,等下去看看二分的题解 但是那个数组的大小是我瞎开的,但是居然没有问题233 #include <cstdio> #include <cmat ...
- codeforces DIV2 D 最短路
http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...
- codeforces div2 677 D
http://codeforces.com/problemset/problem/677/D 题目大意: 给你一个n*m的图,上面有p种钥匙(p<=n*m),每种钥匙至少有一个,期初所有为1的钥 ...
随机推荐
- C# GZip Compress DeCompress
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Java知识串讲
一.JDK个版本之间的区别: 1.JDK1.5的新特性: 泛型ArrayList list = new ArrayList();-->ArrayList<int> list = ne ...
- ubuntu set up 3 - cuda
https://www.pugetsystems.com/labs/hpc/How-to-install-CUDA-9-2-on-Ubuntu-18-04-1184/ How to install C ...
- 阿里云Linux服务器安装Redis 完整步骤(包括处理远程连接问题)
跟随本篇文章步骤,包你成功安装并连接使用. 1.获取redis资源 wget http://download.redis.io/releases/redis-4.0.8.tar.gz 2.解压 tar ...
- vim光标操作
v可视模式 ve可视模式但不包括selection o操作符等待模式 i插入模式 r替换模式(命令模式下,按r,输入一个字符将替换光标所在处字符) c命令行常规模式 ci命令行插入模式 cr命令行替换 ...
- 机器学习作业(四)神经网络参数的拟合——Matlab实现
题目下载[传送门] 题目简述:识别图片中的数字,训练该模型,求参数θ. 第1步:读取数据文件: %% Setup the parameters you will use for this exerci ...
- [POI2006] SZK-Schools - 费用流
差不多就是个二分图带权匹配?(我还是敲费用流吧) 每个点向着自己能到的学校连边,费用按题意设定 跑最小费用最大流即可 #include <bits/stdc++.h> using name ...
- 启动Hive时报错(com.mysql.jdbc.Driver") was not found in the CLASSPATH)
这是因为没有mysql-connector的jar包.需要把jar包复制到hive目录lib文件夹中. 参考博客:https://blog.csdn.net/Realoyou/article/deta ...
- 解决pjax重复绑定
个人博客 地址:http://www.wenhaofan.com/article/20180929002529 1.所有js统一在pjax容器外引入 在pjax容器外引入的js只会被引入一次,所以不会 ...
- 将本地文件git到远程github仓库
使用git管理项目是开发人员必备的技能,下面就介绍如何使用git将本地文件管理并且同步到github上面. 小白可以参考 创建SSH-key并且在github中添加认证 在本地用户的.ssh文件下面生 ...