Ural1209(数学推导)
来源:互联网 发布:软件测试策略 编辑:程序博客网 时间:2024/06/05 17:41
题目链接:点击打开链接
解题思路:
此题甚好。推导公式,首先观察序列110100100010000·····,我们把为1的下标单独拿出来看。依次为1、2、4 、7、 11·····,可以分解为1+(0) 、1+(0+1)、1+(0+1+2)、1+(0+1+2+3)、1+(0+1+2+3+4),可以推导出规律1 + x * (x - 1) / 2。
那么对于每个n,我们只要判断是否存在x使n == 1 + x * (x - 1) / 2即可。对于最后判断开根号是否为整数的判断方法,我们可以用temp - (int)temp == 0来判断,此法甚妙!
完整代码:
#include <algorithm>#include <iostream>#include <cstring>#include <climits>#include <cstdio>#include <string>#include <cmath>#include <map>#include <queue>using namespace std;typedef long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;const int maxn = 700001;int ans[maxn];int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif int T; cin >> T; LL n; int cnt = 0; for(int i = 0 ; i < T ; i ++) { cin >> n; double temp = sqrt(1 + 8 * (n - 1)); if(temp - (int)temp == 0) ans[cnt++] = 1; else ans[cnt++] = 0; } for(int i = 0 ; i < cnt ; i ++) printf("%d%s" , ans[i] , i == cnt - 1 ? "\n" : " ");}
0 0
- Ural1209(数学推导)
- POJ 1183 数学推导
- HDU4602+数学+推导公式
- hdu5117(数学推导+dp)
- HDU2018(数学推导)
- 惯性力的数学推导
- 惯性力的数学推导
- bzoj1432 function 数学推导
- HDU 4919 (数学推导)
- lstm的数学推导
- lstm的数学推导
- 算法数学推导
- 非常可乐 数学推导
- RNN 神经网络数学推导
- 食物分配,数学推导题
- hdu_4377 Sub Sequence (数学推导)
- hdu 1719 Friend 数学推导
- HDU 5312(数学推导+技巧)
- HTKBOOK汉化版
- C++ 类的析构函数学习笔记6
- C++对象生命周期管理--通过引用计数指针对象来封装管理对象生命周期
- 【OpenCV】颜色空间RGB与HSV(HSL)的转换
- Lambda表达式详解
- Ural1209(数学推导)
- uva 757 Gone Fishing (贪心)
- C++之友元函数和友元类
- R中的apply、lapply和sapply
- [数据结构] 图的Kruskal算法实现
- MPlayer移植到EPC9600笔记
- 【OpenCV】 split和merge操作
- [LeetCode] 021. Merge Two Sorted Lists (Easy) (C++/Python)
- HttpClient模块的HttpGet和HttpPost及Connection to refuse解决