Amir_20's blog

By Amir_20, history, 10 years ago, In English

In my Visual studio pow() works correctly
but here even a trivial power won't work !

I tired to use such this in my code
"#include <math.h>"
int k=5 ;
power = pow(10.0 , k );"
I got wrong answer
but when I changed it to
"for(i=0 ; i < k ;i++)
power *= 10 ;"

it worked ! But how ? why?!
the url of the code I submitted: http://mirror.codeforces.com/contest/595/submission/14331963

Full text and comments »

  • Vote: I like it
  • -17
  • Vote: I do not like it

By Amir_20, history, 10 years ago, In English

It is about a simple problem in codeforces "595B — Pasha and Phone"
in the second test my VS 2013 give the right answer but in here gives a wrong one !
input
8 2
1 22 3 44
5 4 3 2
output (codeforces):
30972
output (VS 2013):
32400
answer :
32400

 '#include <iostream>'
  '#include <cmath>'

    using namespace std;

     int main() {
	long long n, power,pow1, c, a[1100], b[1100], i, ans = 1, ai, copyai, z, k;
	cin >> n >> k;
	for (i = 0; i < (n / k); i++)
		cin >> a[i];
	for (i = 0; i < (n / k); i++)
		cin >> b[i];

	power = pow(10.0, k);
	pow1 = pow(10.0, k - 1);

	
	for (i = 0; i< (n / k); i++){
		c = 0;
		z = 0;
		for (z = 0; (ai = a[i] * z) < power; z++){
			if (ai / pow1 != b[i])
				c++;
		}
		ans *= c;
	}
	cout << ans;
  }

Full text and comments »

  • Vote: I like it
  • -25
  • Vote: I do not like it

By Amir_20, history, 10 years ago, In English

hi(){ excuse me for my trivial question ; can anyone help me and say what's the problem for the answer of "588c" (duff and lifting weights ) ?! ; }

include

using namespace std; int main(){ long n, i, a, m[1001000], b = 0, c = 0;

cin >> n;

for (i = 0; i < n; i++){
    cin >> a;
    m[a]++;
    if (c < a);
       c = a;
}
for (i = 0; i < c; i++){
    m[i] = m[i] % 2;
    m[i + 1] += m[i] / 2;
}
for (i = 0; i < c + 10; i++){
    if (m[i] != 0)
       b++;
}
cout << b;

}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it