UVA138(数论问题二分打表)
来源:互联网 发布:耽美小说完结推荐知乎 编辑:程序博客网 时间:2024/05/17 06:55
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19591
解题思路:
题意是给你一个last number记为n,在1~n之间给出house number记为m,求1~m的和 == n ~ m的和,输出10个满足条件的m和n,每个数字宽度为10。
由求和公式,我们很明显可以推导出m和 n的关系为2 * m * m == n * (n + 1)。从8开始枚举n,然后在n内进行二分求m,如果遇到满足上式,则输出,计数器--。
中间涉及到乘方,所以开成long long防溢出。后来发现如果在程序中直接求的话会很慢,索性把结果打成一个表存在二维数组里,最后按格式输出。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;/*void init () //打表{ LL n , m; int cnt = 10; for(LL n = 8 ; cnt > 0 ; n ++ ) { LL l = 1 ; LL r = n; while(l <= r) { m = (l + r) / 2; LL t1 = 2 * m * m; LL t2 = n * (n + 1); if(t1 == t2) { printf("%10lld%10lld\n",m , n); cnt --; break; } else if(t1 < t2) l = m + 1; else r = m - 1; } }}*/LL d[10][2] = {6 , 8 , 35 , 49 , 204 , 288 , 1189 , 1681 , 6930 , 9800 , 40391 , 57121 , 235416 ,332928 , 1372105 , 1940449 , 7997214 , 11309768 , 46611179 , 65918161};int main(){ for(int i = 0 ; i < 10 ; i ++) { printf("%10lld%10lld\n" , d[i][0] , d[i][1]); }}
0 0
- UVA138(数论问题二分打表)
- uva138(数论)
- 51nod 1799 思维 二分 数论 分块打表
- 玲珑#19 A 数论打表 B RMQ+二分
- Friends number 数论 打表
- hdu 1215 数论 +打表
- UVA305 - Joseph(数论 + 打表)
- UVA 1583 打表 数论
- FZU-1881-Problem 1881 三角形问题,打表二分查找~~
- HDU 1215(数论,打表 - -|)
- HDU 2136(数论,筛选打表)
- NEU 1008 Friends number 数论 打表
- hdu 2136 数论+筛选质数+打表
- [hdu 4215]Number Theory? 数论+打表
- Friends number (数论,打表)
- lightoj-1289(数论+素数打表)
- Num(数论(或打表))
- hdu 5878 二分+打表
- DEDECMS列表页随机调用多张缩略图
- java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
- Ceph命令集合
- 集合框架
- C#+OpenGL编程之再见小桃子(The Tao Framework)
- UVA138(数论问题二分打表)
- 常用命令收集
- BZOJ 2438 中山市选 2011 杀人游戏 Tarjan
- 自编译pgmodeler使用过程问题记录
- 如何解决浏览器为GoogleChrome的性能测试而工具不支持的问题
- 集合框架 泛型
- Java序列化学习笔记
- Android Fragment完全解析,关于碎片你所需知道的一切
- Adb打开应用中SQLite文件的方法