题目链接: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. kerberos+ladp+hadoop-ha 安全认证部署配置

    随着hadoop集群里的数据量越来越大,各业务数据都集中了里面,自然要为各业务都要提供数据支持,又希望各业务数据是相对独立安全的,这最时候就需要做安全认证了 hadoop ha 测试集群部署规划 ha ...

  2. Map:比较新增加日期的和需要删除的日期 使用方法

    1.场景描述:根据在日历选择的日期,数据库来保持我们选择日期. 2.方法,硬删除的方法,每次全部删除,然后再重新添加选择的新的日期.这样导致如果需要保存create_time的情况,那么每次操作的都是 ...

  3. mydate97时间控件最大值最小值限制及Javascript日期判断大小

    <script language="javascript" type="text/javascript" src="<%=basePath ...

  4. 鼠标滚轮事件MouseWheel

    其实在大多数浏览器(IE6, IE7, IE8, Opera 10+, Safari 5+,Chrome)中,都提供了 "mousewheel" 事件.但杯具的是 Firefox ...

  5. UVALive 6187 Never Wait for Weights 带权并查集

    题意:每次给出每两个数之间的大小差值.在给出关系的过程中插入询问:数a和数b的差值,若不能确定,输出UNKNOWN 解法:相对大小关系的处理:并查集 1.给出两点的相对大小关系后,找到两个点的根节点, ...

  6. http://blog.csdn.net/wxwzy738/article/details/16968767

    http://blog.csdn.net/wxwzy738/article/details/16968767

  7. lintcode:接雨水

    接雨水 给出 n 个非负整数,代表一张X轴上每个区域宽度为 1 的海拔图, 计算这个海拔图最多能接住多少(面积)雨水. 如上图所示,海拔分别为 [0,1,0,2,1,0,1,3,2,1,2,1], 返 ...

  8. IE9 JSON未定义

    原文:http://social.msdn.microsoft.com/Forums/ie/en-US/fc41127c-0243-4d2e-8e7c-2b311f12e390/ie9-json-no ...

  9. mq_send

    NAME mq_send - 将消息发送到消息队列 (REALTIME) SYNOPSIS #include <mqueue.h>int mq_send(mqd_t mqdes, cons ...

  10. CSS布局:让页底内容永远固定在底部

    我们在设计一些页面内容甚少的网页时(典型应用就是登陆页面),由于显示器的分辨率大,在正常情况下,假如页面内容高度小于浏览器高度时,页面底部以下会留下很大的空间... 先看示例:http://www.h ...