[51NOD1087]1 10 100 1000(规律,二分)
题目链接: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(规律,二分)的更多相关文章
- 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 ...
- 1087 1 10 100 1000(打表 set 数学)
1087 1 10 100 1000 题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 1,10,100,1000... ...
- Timus - 1209 - 1, 10, 100, 1000...
先上题目: 1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite ...
- 51nod 1087 1 10 100 1000【打表】
题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 1,10,100,1000...组成序列1101001000...,求 ...
- 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 ...
- 51NOD 1087 1 10 100 1000
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087 暴力大法 #include<bits/stdc++.h> ...
- 背水一战 Windows 10 (100) - 应用间通信: 分享
[源码下载] 背水一战 Windows 10 (100) - 应用间通信: 分享 作者:webabcd 介绍背水一战 Windows 10 之 应用间通信 分享 示例1.本例用于演示如何开发一个分享的 ...
- 用js实现随机选取10–100之间的10个数字,存入一个数组,并排序
var iArray = []; function getRandom(istart, iend) { var iChoice = iend - istart + 1; //加1是为了取到100 va ...
- 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 ...
随机推荐
- Leetcode#91 Decode Ways
原题地址 动态规划题,注意0导致的小陷阱. 代码: int numDecodings(string s) { ] < ] > ; ] >= ] <= : ; ; int nex ...
- JS范围
JS API-->DOM/PoneGap/Cordova/Android/NodeJS JS OOP
- javascript陷阱,一不小心你就中招了
- jQuery提升性能技巧及个人总结
1.将jquery对象缓存起来在for循环中,不要每次都要访问数组的length属性,我们应该先将对象缓存进一个变量然后再操作,如下所示: 代码如下:var myLength = myArray.le ...
- mysql修改数据库表权限
ps:通常我用的是:1.“grant all on *.* to root@'%' identified by 'yourpassword';”——这个还可以顺带设置密码.2.“flush privi ...
- web访问速度优化分析
请求从发出到接收完成一共经历了DNS Lookup.Connecting.Blocking.Sending.Waiting和Receiving六个阶段,时间共计38ms.请求完成之后是DOM加载和页面 ...
- Javascript获取URL参数值
getQueryString: function (name) { var reg = new RegExp("(^|&)" + name.toLowerCase() + ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- 【剑指offer】从尾到头打印链表
我的思路:先翻转链表,再打印. 网上思路:利用栈的后进先出性质:或者用递归,本质也是栈. 我的代码: #include <vector> using namespace std; stru ...
- ios网站,博客
中文 网站系列 objcio.cncocoachina.comcode4app.com泰然网 博客系列唐巧地球人都知道哈.http://blog.devtang.com/巧哥新出书了,速度入手吧. 虾 ...