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的钥 ...
随机推荐
- HashMap源码刨析(面试必看)
目录 1.Hash的计算规则? 2.HashMap是怎么形成环形链表的(即为什么不是线程安全)?(1.7中的问题) 3.JDK1.7和1.8的HashMap不同点? 4.HashMap和HashTab ...
- H3C RIP配置
一.RIP简介 RIP(Routing Information Protocol,路由信息协议)是一种较为简单的内部网关协议(Interior Gateway Protocol,IGP),主要用于规模 ...
- 机器学习作业(八)异常检测与推荐系统——Matlab实现
题目下载[传送门] 第1题 简述:对于一组网络数据进行异常检测. 第1步:读取数据文件,使用高斯分布计算 μ 和 σ²: % The following command loads the datas ...
- Loj514「LibreOJ β Round #2」模拟只会猜题意 - 模拟
注意初始化即可. #include <bits/stdc++.h> using namespace std; ],a[],t1,t2,t3,t4; int main(){ memset(a ...
- PP: Think globally, act locally: A deep neural network approach to high-dimensional time series forecasting
Problem: high-dimensional time series forecasting ?? what is "high-dimensional" time serie ...
- 用Navicat连接mysql报错:2003-Can't connect to MySql server on '10.100.0.109'(10039)
问题描述 在 window 系统上,用 Navicat 连接 Mysql 数据库,弹出以下提示 问题原因 Mysql 数据库未启动 解决方案:启动 Mysql 数据库 1.点击桌面左下角运行 cmd ...
- gogs迁移至gitlab
一.先来聊一聊迁移的思路,不管是gogs迁移至gitlab,还是gitlab迁移至gogs,亦或gitlab迁移至gitlab,手动迁移的步骤都是如下图所示(在gitlab上新建一个空项目就会有这样的 ...
- 155.XSS攻击原理
XSS攻击: XSS(Cross Site Script)攻击叫做跨站脚本攻击,他的原理是用户使用具有XSS漏洞的网站的时候,向这个网站提交一些恶意代码,当用户在访问这个网站的某个页面的时候,这个恶意 ...
- spring security和java web token整合
思路: spring security 1.用户输入用户名密码. 2.验证:从库中(可以是内存.数据库等)查询该用户的密码.角色,验证用户名和密码是否正确.如果正确,则将填充Authenticatio ...
- django 版本 对应pyhton版本
对应关系