ZOJ3768 Continuous Login
来源:互联网 发布:unity3d游戏开发教程 编辑:程序博客网 时间:2024/06/03 18:54
Pierre is recently obsessed with an online game. To encourage users to log in, this game will give users a continuous login reward. The mechanism of continuous login reward is as follows: If you have not logged in on a certain day, the reward of that day is 0, otherwise the reward is the previous day's plus 1.
On the other hand, Pierre is very fond of the number N. He wants to get exactly N points reward with the least possible interruption of continuous login.
Input
There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
There is one integer N (1 <= N <= 123456789).
Output
For each test case, output the days of continuous login, separated by a space.
This problem is special judged so any correct answer will be accepted.
Sample Input
4201969
Sample Output
4 43 4 232 3
Hint
20 = (1 + 2 + 3 + 4) + (1 + 2 + 3 + 4)
19 = (1 + 2 + 3) + (1 + 2 + 3 + 4) + (1 + 2)
6 = (1 + 2 + 3)
9 = (1 + 2) + (1 + 2 + 3)
Some problem has a simple, fast and correct solution.
题目的意思是给出一个数n是的n分成若干的数的和,每个数是重1累加奥x的,保证数字个数最少
找规律发现最多出现3项,分别对1项2项3项讨论,枚举加二分
#include <iostream>#include<queue>#include<cstdio>#include<algorithm>#include<cmath>#include<set>#include <cstring>using namespace std;#define LL long longint a[100005];int main(){ int T,n; a[0]=0; for(int i=1;i<100005;i++) a[i]=a[i-1]+i; scanf("%d",&T); while(T--) { int flag=0; scanf("%d",&n); for(int i=0;i<100000;i++) { if(a[i]==n){ flag=1; printf("%d\n",i); break; } if(a[i]>n) break; } if(flag) continue; for(int i=0;a[i]<n;i++) { int x=n-a[i]; int pos=lower_bound(a,a+100000,x)-a; if(a[pos]==x) { flag=1; printf("%d %d\n",i,pos); break; } } if(flag) continue; for(int i=0;a[i]<n;i++) { for(int j=0;a[j]<n-a[i];j++) { int x=n-a[i]-a[j]; int pos=lower_bound(a,a+100000,x)-a; if(a[pos]==x) { flag=1; printf("%d %d %d\n",i,j,pos); break; } } if(flag) break; } } return 0;}
- ZOJ3768:Continuous Login(二分)
- ZOJ3768 Continuous Login
- ZOJ3768-Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ 3768 Continuous Login
- ZOJ Problem Set - 3768 Continuous Login
- ZOJ Problem Set - 3768 Continuous Login
- ZOJ 3768 Continuous Login(暴力或夹逼原理)
- ZOJ 3768Continuous Login(找规律然后二分)
- [迭代加深dfs] zoj 3768 Continuous Login
- Kubernetes使用Harbor仓库
- POJ 1039 Pipe(直线和线段相交判断,求交点)
- Caffe windows踩坑
- react native使用原生模块
- 蓝桥杯 第八届
- ZOJ3768 Continuous Login
- Idea 将新写的项目中的一个java文件搞成jar包方法
- Java遇到Resource leak: 'input' is never closed怎么解决
- 关于Curl的get和post请求
- Pycharm 中的 全局搜索(ctrl+shift+f) 功能无法使用的原因
- 机器学习一些数据集
- 简单工厂、工厂方法、抽象工厂、策略模式、策略与工厂的区别
- 妈妈群的诞生
- mydumper原理和使用