题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087

  用高中的数列知识就可以推出公式,不难发现f(n)=f(n-1)+n-1,f(1)=1。列出f(n)~f(2)的所有表达式,左右值分别求和就可以消去中间量,最后得出f(n)=(n*n-n)/2+1。

  刚才在上XML的时候一个同学告诉我,她初中数学老师告诉她假如数列的公差也是一个等差数列,那么这个式子一定表示为a*x^2+b*x+c的形式。我试着带进去了前三个值,卧曹还真是,学到了……

  对于本题,得到了公式,再二分优化一下即可。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long LL;
LL n; LL f(LL n) {
return (n * n - n) / + ;
} int main() {
// freopen("in", "r", stdin);
int T;
scanf("%d", &T);
while(T--) {
scanf("%I64d", &n);
bool flag = ;
LL ll = , rr = n;
while(ll <= rr) {
LL mm = (ll + rr) >> ;
LL val = f(mm);
if(val == n) {
flag = ;
break;
}
else if(val > n) rr = mm - ;
else ll = mm + ;
}
printf("%d\n", flag);
}
return ;
}

[51NOD1087]1 10 100 1000(规律,二分)的更多相关文章

  1. Ural 1209. 1, 10, 100, 1000... 一道有趣的题

    1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite seque ...

  2. 1087 1 10 100 1000(打表 set 数学)

    1087 1 10 100 1000 题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 1,10,100,1000... ...

  3. Timus - 1209 - 1, 10, 100, 1000...

    先上题目: 1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite ...

  4. 51nod 1087 1 10 100 1000【打表】

    题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 1,10,100,1000...组成序列1101001000...,求 ...

  5. 51Nod 1087 1 10 100 1000 | 数学

    Input示例 3 1 2 3 Output示例 1 1 0 #include "bits/stdc++.h" using namespace std; #define LL lo ...

  6. 51NOD 1087 1 10 100 1000

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087 暴力大法 #include<bits/stdc++.h> ...

  7. 背水一战 Windows 10 (100) - 应用间通信: 分享

    [源码下载] 背水一战 Windows 10 (100) - 应用间通信: 分享 作者:webabcd 介绍背水一战 Windows 10 之 应用间通信 分享 示例1.本例用于演示如何开发一个分享的 ...

  8. 用js实现随机选取10–100之间的10个数字,存入一个数组,并排序

    var iArray = []; function getRandom(istart, iend) { var iChoice = iend - istart + 1; //加1是为了取到100 va ...

  9. ResourceWarning: unclosed <socket.socket fd=864, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.100.x.x', 37321), raddr=('10.1.x.x', 8500)>解决办法

    将代码封装,并使用unittest调用时,返回如下警告: C:\python3.6\lib\collections\__init__.py:431: ResourceWarning: unclosed ...

随机推荐

  1. html之colspan && rowspan讲解

    1.colspan && rowspan均在td标签中使用 2.每个单元格大小一致的前提 <table border="1" bordercolor=&quo ...

  2. VSync Count 垂直同步

    原地址:http://blog.csdn.net/yesy10/article/details/7794556 Unity3D中新建一个场景空的时候,帧速率(FPS总是很低),大概在60~70之间.一 ...

  3. Sqli-labs less 26

    Less-26 TIPS:本关可能有的朋友在windows下无法使用一些特殊的字符代替空格,此处是因为apache的解析的问题,这里请更换到linux平台下. 本关结合25关,将空格,or,and,/ ...

  4. VS2012 win7 修改TFS登陆账号

    1.修改登陆账号: 在网上搜了好多,都没有找到解决方法,自己琢磨了一会找到了修改登陆TFS(Team Foundation Server)(团队资源管理器)的账号,和大家分享一下吧. 点击“开始”-- ...

  5. GRID用法(取行、列值;定位选中某行等等)

    Delphi Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值 cxGrid1DBTableView1.Controller.FocusedRowIndex 当前行号 cxGrid1DB ...

  6. Codeforces 475D CGCDSSQ(分治)

    题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随 ...

  7. LA 4256

    Traveling salesmen of nhn. (the prestigious Korean internet company) report their current location t ...

  8. POJ 1459

    #include<iostream> #define MAXN 105 #include"queue" #define big_num 100000000 using ...

  9. sqoop导入hdfs上的数据到oracle

    /opt/sqoop-/bin/sqoop export --table mytablename --connect jdbc:oracle:thin:@**.**.**.**:***:dbasena ...

  10. ***百度统计图表Echarts的php实现类,支持柱形图、线形图、饼形图

    /** * 百度数据统计图表echart的PHP实现类 * * 原作者: * @author: chenliujin <liujin.chen@qq.com> * @since 2013- ...