QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383777 | #6749. Target | Teiosama# | RE | 1ms | 3880kb | C++17 | 1.2kb | 2024-04-09 17:31:43 | 2024-04-09 17:31:43 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main()
{
double a,b;
cin>>a>>b;
double a1=a;
int ans[60]={0};
int cnt = 0;
int ww=0;
int flag=0;
if(b==0.5)
{
for(int i=1;i<=49;++i)cout<<"2";
cout<<"1";
return 0;
}
while(fabs(a-b)>0.0001)
{
ww++;
if(ww>50)
{
flag=1;break;
}
//cout<<"di"<<ww<<"ci ";
if(a>b)
{
a*=0.5;
//a*=0.5;
//ans[cnt++] = 1;
ans[cnt++] = 1;
}
else
{
a = a*0.5+0.5;
//a = a*0.5+0.5;
ans[cnt++] = 2;//ans[cnt++] = 2;
}
//cout<<fixed<<setprecision(6)<<a<<'\n';
}
if(flag==0)
{
for(int i = 0;i<cnt;i++)
{
cout<<ans[i];
}
cout<<endl;
}
else{
cnt=0;
while(fabs(a1-b)>0.0001)
{
//cout<<"di"<<ww<<"ci ";
if(a1>b)
{
a1*=0.5;
a1*=0.5;
a1*=0.5;
//a1*=0.5;
//ans[cnt++] = 1;
ans[cnt++] = 1;
ans[cnt++] = 1;
ans[cnt++] = 1;
}
else
{
a1 = a1*0.5+0.5;
// a1 = a1*0.5+0.5;
ans[cnt++] = 2;//ans[cnt++] = 2;
}
//cout<<fixed<<setprecision(6)<<a<<'\n';
}
for(int i = 0;i<cnt;i++)
{
cout<<ans[i];
}
cout<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3820kb
input:
0.5 0.25
output:
1
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
1 0.75
output:
12
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
1 0
output:
11111111111111
result:
ok ok
Test #4:
score: -100
Runtime Error
input:
0.361954 0.578805