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的钥 ...
随机推荐
- Java架构师资料
Java架构师ZHONGVIP课程资料链接 2017年第一学期的资料链接:(视频和文档是一起的) 一.互联网工程专题 链接:https://pan.baidu.com/s/1PGE ...
- 用友UAP NC 单据新增时业务单元不能带出问题处理
用户需求新建一个主子表单据,由于刚从63环境升级到65环境,所以对于 65环境走单据流程生成节 点出的错误不了解. 直接建了集团级的主子表单据后,实施说需要的是业务单元级的主子表单据,跟用友开发沟通后 ...
- 841. 字符串哈希(hash)
给定一个长度为n的字符串,再给定m个询问,每个询问包含四个整数l1,r1,l2,r2l1,r1,l2,r2,请你判断[l1,r1l1,r1]和[l2,r2l2,r2]这两个区间所包含的字符串子串是否完 ...
- java中的多构造函数以及类字段的初始化顺序
1.同一个类可以有多个构造函数,多个构造函数之间通过参数来区分.这是方法重载的一个实例.构造函数之间可以相互调用. 2.类的初始化块:可以在类中使用“{”和“}”将语句包围起来,直接将其作为类的成员. ...
- 多项式对数函数 - NTT
#include <bits/stdc++.h> using namespace std; #define int long long const int N=4000005; // 4 ...
- "换行"和"回车"的来历
\r: return 到当前行的最左边. \n: newline 向下移动一行,并不移动左右. Linux中\n表示:回车+换行: Windows中\r\n表示:回车+换行. Mac中\r表示:回车+ ...
- SpringBoot学习- 4、整合JWT
SpringBoot学习足迹 1.Json web token(JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准(RFC 7519),该token被设计为紧凑且安全的,特别适用于 ...
- url 加参数
url = 访问地址 + ? key1=value1 & key2 = value2 304(未修改)自从上次请求后,请求的网页未修改过.服务器返回此响应时,不会返回网页内容. 加参数,骗过服 ...
- batch_idx作用
batch_idx作用 待办 batch_idx * len(data) 这里的batch_idx 就是数组分组之后的组号,len(data)就是每组的数据量,这个式子表示的就是总共已经训练的数据总数 ...
- ReLU(inplace=True),这里的inplace=true的意思
ReLU(inplace=True),这里的inplace=true的意思 待办 inplace=True means that it will modify the input directly, ...