Heron and His Triangle HDU - 6222
题目链接:https://vjudge.net/problem/HDU-6222
思路:打表找规律。
然后因为数据范围较大可以考虑用字符串模拟,或者__int128要注意用一个快读快输模板。
1 #include <bits/stdc++.h>
2 #include <time.h>
3 #include <set>
4 #include <map>
5 #include <stack>
6 #include <cmath>
7 #include <queue>
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 #include <cstring>
12 #include <utility>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 #include <list>
17 using namespace std;
18 //cout<<setprecision(10)<<fixed;
19 #define eps 1e-6
20 #define PI acos(-1.0)
21 #define lowbit(x) ((x)&(-x))
22 #define zero(x) (((x)>0?(x):-(x))<eps)
23 #define mem(s,n) memset(s,n,sizeof s);
24 #define rep(i,a,b) for(int i=a;i<=b;i++)
25 #define rep2(i,a,b) for(int i=a;i>=b;i--)
26 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
27 typedef long long ll;
28 typedef unsigned long long ull;
29 const int maxn=1e6+5;
30 const ll Inf=0x7f7f7f7f7f7f7f7f;
31 const ll mod=1e9;
32 //const int N=3e3+5;
33 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
34 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
35 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
36 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
37 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
38 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
39 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
40 inline int read()
41 {
42 int X=0; bool flag=1; char ch=getchar();
43 while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
44 while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
45 if(flag) return X;
46 return ~(X-1);
47 }
48 inline void write(int X)
49 {
50 if(X<0) {X=~(X-1); putchar('-');}
51 if(X>9) write(X/10);
52 putchar(X%10+'0');
53 }
54 /*
55 inline int write(int X)
56 {
57 if(X<0) {putchar('-'); X=~(X-1);}
58 int s[20],top=0;
59 while(X) {s[++top]=X%10; X/=10;}
60 if(!top) s[++top]=0;
61 while(top) putchar(s[top--]+'0');
62 }
63 */
64 int Abs(int n) {
65 return (n ^ (n >> 31)) - (n >> 31);
66 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
67 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
68 需要计算 n 和 -1 的补码,然后进行异或运算,
69 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
70 }
71 ll binpow(ll a, ll b) {
72 ll res = 1;
73 while (b > 0) {
74 if (b & 1) res = res * a%mod;
75 a = a * a%mod;
76 b >>= 1;
77 }
78 return res%mod;
79 }
80 void extend_gcd(ll a,ll b,ll &x,ll &y)
81 {
82 if(b==0) {
83 x=1,y=0;
84 return;
85 }
86 extend_gcd(b,a%b,x,y);
87 ll tmp=x;
88 x=y;
89 y=tmp-(a/b)*y;
90 }
91 ll mod_inverse(ll a,ll m)
92 {
93 ll x,y;
94 extend_gcd(a,m,x,y);
95 return (m+x%m)%m;
96 }
97 ll eulor(ll x)
98 {
99 ll cnt=x;
100 ll ma=sqrt(x);
101 for(int i=2;i<=ma;i++)
102 {
103 if(x%i==0) cnt=cnt/i*(i-1);
104 while(x%i==0) x/=i;
105 }
106 if(x>1) cnt=cnt/x*(x-1);
107 return cnt;
108 }
109 void scan(__int128 &x)//输入
110 {
111 x = 0;
112 int f = 1;
113 char ch;
114 if((ch = getchar()) == '-') f = -f;
115 else x = x*10 + ch-'0';
116 while((ch = getchar()) >= '0' && ch <= '9')
117 x = x*10 + ch-'0';
118 x *= f;
119 }
120 void _print(__int128 x)
121 {
122 if(x > 9) _print(x/10);
123 putchar(x%10 + '0');
124 }
125 __int128 a[maxn];
126 int main()
127 {
128 int t=read();
129 a[1]=4;
130 a[2]=14;
131 __int128 b=1e31;
132 int i;
133 for( i=3;;i++)
134 {
135 a[i]=a[i-1]*4-a[i-2];
136 if(a[i]>b) break;
137 }
138 while(t--)
139 {
140 __int128 n;
141 scan(n);
142 for(int j=1;j<=i;j++)
143 {
144 if(a[j]>=n) {_print(a[j]);puts("");break;}
145 }
146 }
147 return 0;
148 }
Heron and His Triangle HDU - 6222的更多相关文章
- Heron and His Triangle HDU - 6222(pell 大数)
---恢复内容开始--- Heron and His Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/2 ...
- HDU 6222 Heron and His Triangle (pell 方程)
题面(本人翻译) A triangle is a Heron's triangle if it satisfies that the side lengths of it are consecutiv ...
- Heron and His Triangle 2017 沈阳区域赛
A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...
- 2017 ACM/ICPC 沈阳 F题 Heron and his triangle
A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...
- 【HDOJ6222】Heron and His Triangle(Java,二分,递推)
题意:让你找这样的一个三角形,三条边为t,t-1,t+1,并且面积为整数,最后满足t大于等于n. n<=1e30 思路:直接推式子不会,打表找规律 f(n)=4*f(n-1)-f(n-2)(n& ...
- 2017ACM/ICPC亚洲区沈阳站(部分解题报告)
HDU 6225 Little Boxes 题意 计算四个整数的和 解题思路 使用Java大整数 import java.math.BigInteger; import java.util.Scann ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛
HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...
- 近几年ACM/ICPC区域赛铜牌题
2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...
- ACM-ICPC 2017 Asia Shenyang Solution
A: BBP Formula https://www.cnblogs.com/LzyRapx/p/7802790.html #include <bits/stdc++.h> using n ...
随机推荐
- DuckDuckGo Privacy Browser
DuckDuckGo Privacy Browser https://apps.apple.com/app/duckduckgo-privacy-browser/id663592361 https:/ ...
- js Promise finally All In One
js Promise finally All In One finally let isLoading = true; fetch(myRequest).then(function(response) ...
- node.js 怎么扩大默认的分配的最大运行内存
node.js 怎么扩大默认的分配的最大运行内存 $ node --max-old-space-size=4096 app.js $ NODE_OPTIONS=--max-old-space-size ...
- javascript module system all in one
javascript module system all in one AMD & CMD https://github.com/amdjs/amdjs-api/wiki/AMD http:/ ...
- cookie & session & token compare
cookie & session & token compare cookie.session.token 区别和优缺点 存储位置 cookie 存在 client 端 session ...
- HTTPS clone !== SSH clone
HTTPS clone !== SSH clone https clone bug SSH clone OK testing SSH key https://www.cnblogs.com/xgqfr ...
- element-ui的树型结构图,带有复选框的,没有子项的,横排展示
// 修改树形图样式,如果不含有下箭头的块,要变成行内样式 treeChildInline(){ let hasCaretRight = $("#permission_panel" ...
- VAST生态驱动下,NGK算力增量效应初现!
VAST维萨币上线的消息放出来之后,NGK算力的价格一直在上涨,其实这也不难理解,因为VAST维萨币需要VAST星光值进行兑换,VAST星光值又需要SPC算力福利代币进行挖矿释放的,SPC算力福利代币 ...
- “NGK公链+5G”——打造智慧城市
智慧城市目前被全球各国当成城市建设的重点,旨在城市在智能化的同时,还能给民众带来幸福感和安全感.随着5G的到来,城市智能化又到了一个新的高度.比如无人驾驶.无人机等方面将会产生质的变化,因为5G的加入 ...
- Baccarat凭什么吸引做市商?2021年将如何发展?
在过去的一年里,基于资金池的AMM自动化做市商几乎统治了所有DeFi活动,他们没有订单簿,而是根据算法曲线提供资产.尽管在流动性和交易方面取得了令人惊叹的成绩,但是其自身具有无常损失.多代币敞口以及低 ...