ZOJ3768-Continuous Login
来源:互联网 发布:朱自清背影网络 编辑:程序博客网 时间:2024/05/21 19:21
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.
Author: ZHOU, Yuchen
Source: The 14th Zhejiang University Programming Contest
题意:找最少的组数,使得找的所有的组等差数列和的全部和为所给数
解题思路:暴力找了下,发现最多也就三,然后暴力+二分
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;int a[16100],cnt;void init(){ memset(a,0,sizeof a); cnt=1; int sum=0; for(int i=1;; i++) { sum+=i; if(sum<=123456789) a[cnt++]=sum; else break; } //printf("%d\n",cnt-1);}int main(){ init(); int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); auto it=lower_bound(a,a+cnt,n); if(*it==n) printf("%d\n",it-a); else { bool flag=0; for(int i=1; a[i]<=n/2; i++) { int m=n-a[i]; auto it=lower_bound(a,a+cnt,m); if(*it==m) { printf("%d %d\n",i,it-a); flag=1; break; } } if(flag) continue; for(int i=1; a[i]<n/2; i++) { int m=n-a[i]; for(int j=i; a[j]<m/2; j++) { int nm=m-a[j]; auto it=lower_bound(a,a+cnt,nm); if(*it==nm) { printf("%d %d %d\n",i,j,it-a); flag=1; break; } } if(flag)break; } if(!flag)printf("cnm\n"); } } 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
- js数字位数太大导致参数精度丢失问题
- LeetCode 551. Student Attendance Record I
- Shiro整合Spring maven
- matlab 数据读取
- Leetcode 282. Expression Add Operators
- ZOJ3768-Continuous Login
- 样本不平衡--SMOTE算法-学习笔记
- iOS获取通讯录
- Nginx(相关概念和安装)
- 【计算机】基本概念的理解 —— 沙盒(sandbox)、交互式计算/编程/应用
- bzoj 3073: [Pa2011]Journeys 线段树优化建图+堆优化dij
- Android屏幕适配经验谈
- 程序员面试金典——二叉树平衡检查
- 3017 Factory Pipelining