C++ doesn't work, while Pascal does!
this program isn't AC (WA test#10) because of the
precision of the answer, but Pascal solution using the
same ideas is AC. If you can help me to deal with the
precision I would be very grateful to you. Still i'd
recommend you to write the problem in Pascal to avoid all
potential precision problems :
#include <iostream>
#include <cmath>
using namespace std;
struct cross{int x,y;};
int main()
{
int m,n,k,i;
cross a[100];
cin >> m >> n >> k;
if (!k) {cout << 100*(m+n); return 0;}
for (i=0;i<k;i++) cin >> a[i].x >> a[i].y;
bool f=false;
cross t;
while (!f)
{
f=true;
for (i=0;i<k-1;i++)
if (a[i].x>a[i+1].x)
{t=a[i]; a[i]=a[i+1]; a[i+1]=t; f=false;}
else if (a[i].x==a[i+1].x && a[i].y>a[i+1].y)
{t=a[i]; a[i]=a[i+1]; a[i+1]=t; f=false;}
}
int d[100];
int mx,j;
d[k-1]=1;
for (i=k-2;i>=0;i--)
{
d[i]=1; mx=0;
for (j=k-1;j>i;j--)
if (a[i].x<a[j].x && a[i].y<a[j].y && d[j]>mx) mx=d[j];
d[i]+=mx;
}
double ans;
ans=(double)100*((double)m+(double)n-(double)2*d[0]+sqrt((double)2)*(double)d[0]);
cout << floor(ans+(double).5);
return 0;
}
Re: But I got AC in C#
Posted by
asd 5 Jan 2006 17:15
So what to do? I've got wa#10 and don't know how properly round the number!!! printf("%.0f",f); doesn't work!!!!
Re: But I got AC in C#
I guess it would be easier to rewrite it in Delphi or Pascal. I didn't manage to find a mistake in my solution.
There're probably big random numbers in the bad test.
Pascal better
Because Pascal is better than your C++(or C)!
Pascal luchshe potomu shto tvoy C++ dibilniy
Re: Pascal better
Posted by
asd 8 Jan 2006 12:53
In fact, I don't think so. I suppouse C++ is more powerfull, but probably test for this problem were made by Pascal program.
Re: Pascal better
I cannot understand why you are so furious about C++.
If you know it well it's surely better than Pascal
(I mean it gives you much more freedom).
The only problem is to learn how to use its power properly.
Re: Pascal better
Well, there are many arguments whether pascal or c++ is better but I think it depends on the coder. Yet, I prefer C++ mainly because it's more powerful and it has STL which is a great advantage, although that lately I'm getting very fond of Java and once I couldn't solve a problem niether on C, c++ or pascal and I tried Java and suddenly made it :).
So sometimes tests really are made for some language
Re: But I got AC in C#
Posted by
Atik 29 Jan 2008 21:59
function Round(X: Extended): Int64;
Description
In Delphi, the Round function rounds a real-type value to an integer-type value.
X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number. This method of rounding is often called "Banker’s Rounding".
Re: C++ doesn't work, while Pascal does!
this is very strange try to send this code before changing this fragment
d[k-1]=1;
for (i=k-2;i>=0;i--)
{
d[i]=1; mx=0;
for (j=k-1;j>i;j--)
if (a[i].x<a[j].x && a[i].y<a[j].y && d[j]>mx) mx=d[j];
d[i]+=mx;
}
to
d[0]=1;
for (i=1;i<k;i++)
{
d[i]=1; mx=0;
for (j=0;j<i;j++)
if (a[i].x>a[j].x && a[i].y>a[j].y && d[j]>mx) mx=d[j];
d[i]+=mx;
}
and this fragment
ans=(double)100*((double)m+(double)n-(double)2*d[0]+sqrt((double)2)*(double)d[0]);
cout << floor(ans+(double).5);
to
ans=100.0*(m+n-2*d[k-1])+d[k-1]*sqrt(20000.0);
cout<<(int)(ans+0.5)<<endl;
and I hope you will get AC
Edited by author 29.01.2009 23:29
How to round in C++
Well, I round with:
(int)(a + 0.5 + 1e-9);
When 'a' is the number I need to round.
Re: How to round in C++
I think this method is better:
double ans;
/*
...
*/
cout.setf(ios::fixed,ios::floatfield);
cout.precision(0);
cout << ans;