CF457A:Golden System(数论 & 进制)
2017-08-13 22:33
260 查看
A. Golden System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number
,
in particular that q2 = q + 1,
and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a0a1...an equals
to
.
Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.
Given two numbers written in golden system notation, determine which of them has larger decimal value.
Input
Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.
Output
Print ">" if the first number is larger, "<" if it is smaller
and "=" if they are equal.
Examples
input
output
input
output
input
output
Note
In the first example first number equals to
,
while second number is approximately 1.6180339882 + 1.618033988 + 1 ≈ 5.236,
which is clearly a bigger number.
In the second example numbers are equal. Each of them is ≈ 2.618.
题意:比较两个特殊的进制数大小。
思路:显然q^i = q^(i-1) + q^(i-2),那么将高位的数累加最低两位即可比较大小。
# include <bits/stdc++.h>using namespace std;
const int maxn = 1e5+30;
typedef long long LL;
char s1[maxn], s2[maxn];
double a[maxn];
int main()
{
scanf("%s%s",s1,s2);
int n1=strlen(s1), n2 = strlen(s2);
for(int i=0; i<n1/2; ++i) swap(s1[i], s1[n
df62
1-i-1]);
for(int i=0; i<n2/2; ++i) swap(s2[i],s2[n2-i-1]);
for(int i=0; i<n1; ++i) a[i] = s1[i]-'0';
for(int i=0; i<n2; ++i) a[i] = a[i] - s2[i] + '0';
for(int i=max(n1,n2)-1; i>=2; --i)
{
a[i-2] += a[i];
a[i-1] += a[i];
}
if(a[0] == a[1] && a[0] == 0)
puts("=");
else
{
double ans = (sqrt(5)+1)/2.0*a[1] + a[0];
if(ans < 0) puts("<");
else puts(">");
}
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number
,
in particular that q2 = q + 1,
and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a0a1...an equals
to
.
Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.
Given two numbers written in golden system notation, determine which of them has larger decimal value.
Input
Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.
Output
Print ">" if the first number is larger, "<" if it is smaller
and "=" if they are equal.
Examples
input
1000 111
output
<
input
00100 11
output
=
input
110 101
output
>
Note
In the first example first number equals to
,
while second number is approximately 1.6180339882 + 1.618033988 + 1 ≈ 5.236,
which is clearly a bigger number.
In the second example numbers are equal. Each of them is ≈ 2.618.
题意:比较两个特殊的进制数大小。
思路:显然q^i = q^(i-1) + q^(i-2),那么将高位的数累加最低两位即可比较大小。
# include <bits/stdc++.h>using namespace std;
const int maxn = 1e5+30;
typedef long long LL;
char s1[maxn], s2[maxn];
double a[maxn];
int main()
{
scanf("%s%s",s1,s2);
int n1=strlen(s1), n2 = strlen(s2);
for(int i=0; i<n1/2; ++i) swap(s1[i], s1[n
df62
1-i-1]);
for(int i=0; i<n2/2; ++i) swap(s2[i],s2[n2-i-1]);
for(int i=0; i<n1; ++i) a[i] = s1[i]-'0';
for(int i=0; i<n2; ++i) a[i] = a[i] - s2[i] + '0';
for(int i=max(n1,n2)-1; i>=2; --i)
{
a[i-2] += a[i];
a[i-1] += a[i];
}
if(a[0] == a[1] && a[0] == 0)
puts("=");
else
{
double ans = (sqrt(5)+1)/2.0*a[1] + a[0];
if(ans < 0) puts("<");
else puts(">");
}
return 0;
}
相关文章推荐
- 【CodeForces】458A - Golden System(数论 & 模拟)
- 51NOD 1491 黄金系统 && Codeforces 458 A. Golden System(斐波那契数列 + 找规律)
- CF 457A(Golden System-特殊的进制)
- 打成jar包的xml配置文件无法找到路径,System.getProperty("user.dir")解决该问题
- Exception: Environment variable "SYSTEMROOT" required to be set to valid path
- 80端口被NT kernel & System 占用pid 4
- 业务操作支撑系统(Business &amp; Operation Support System)
- 【数论】矩阵快速幂&&CODE[VS] 1732
- Unable to find script library '/aspnet_client/system-web/1-1-4322/webvalidation.js'
- 异常详细信息: System.Web.HttpRequestValidationException: 从客户端(fck_content="
- SumTotal's Results-Demand Performance System
- 80端口被NT kernel & System 占用pid= 4的解决方法
- Win32汇编语言学习笔记>>第四课:进制
- System.Data.SqlClient.SqlException: 必须声明变量 '@ImageUrl'。
- Android 分区详解: boot, system, recovery, data, cache & misc
- 【数论】FOJ 2238 Daxia & Wzc's problem
- qemu & qemu-system
- System.out.println("占个地方>>"+(++sum羞愧))
- Server.MapPath() & System.AppDomain.CurrentDomain.BaseDirectory
- API:System V & POSIX