Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
code for ROUND 1 APAC 2017 QUESTION 3 GIVING WRONG ANSWER ON LARGE SUBTASK
#include <bits/stdc++.h>
#define long long long int
using namespace std;
#define Max 1e18
# define con 1000000007
#define mp make_pair
#define pb push_back
#define PI 3.14159265
long ci[102];double r;int m;
double answer()
{
double rr=1.0;double ans=0;
for(int i=m;i>=1;i--)
{
ans+=rr*((double)ci[i]);
rr*=(1.0+r);
}
ans-=((double)ci[0])*rr;
return ans;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
// cout<<((1e-18)*1e9)<<endl;
ifstream filename;
filename.open("input.txt", ios::in);
ofstream file2;
file2.open("output.txt",ios::out);
int t;filename>>t;int i=1;
while(t-->0)
{
filename>>m;
for(int i=0;i<=m;i++)filename>>ci[i];
long l=0,b=2e18;double ans,ans1;
r=1-(1e-18);double right=answer();r=-1+(1e-18);double left=answer();//cout<<setprecision(12)<<fixed<<left<<endl<<right<<endl;
while(l<=b)
{
long mid1=(b+l)/2;double mid=mid1;
mid-=Max;
mid/=(double)Max;
r=mid;
ans=answer();
//cout<<setprecision(12)<<fixed<<l<<" "<<mid1<<" "<<b<<endl;
if((ans>0.0 && left<0.0) ||(ans<0.0 && left>0.0)){right=ans;b=mid1-1;ans1=mid;}else if((ans<0.0 && right>0.0) ||(ans>0.0 && right<0.0)){left=ans;l=mid1+1;ans1=mid;} else{ans1=mid;break;}
}
file2<<"Case #"<<i<<": ";
file2<<setprecision(12)<<fixed<<ans1<<endl;i++;ans=0;
//if(i==169) cout<<v<<" "<<d<<" "<<ans;
}
filename.close();
file2.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.