I met a questions. the link ->
the problem
here is my solution.If i use scanf
, the code can be accepted on codeforces, but replace cin
then not,it occurs wrong answer,but in my local interpreter using cin is ok.
why?
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
scanf("%d", &t);
nt :
while (t--) {
long long hc, dc, hm, dm, w, a;
long k;
scanf("%lld%lld%lld%lld%d%lld%lld", &hc, &dc, &hm, &dm, &k, &w, &a); // ok
// cin >> hc >> dc >> hm >> dm >> k >> w >> a; // cannot work
for (int i = 0; i < k 1; i ) {
int opt = k - i;
long long hc1 = opt * a hc;
long long dc1 = i * w dc;
long long cnt1 = hm / dc1 (hm % dc1 > 0);
long long cnt2 = hc1 / dm (hc1 % dm > 0);
if (cnt1 <= cnt2) {
printf("YES\n");
goto nt;
}
}
printf("NO\n");
}
}
I just try a lot of practices , found the key of question is input of question.
CodePudding user response:
You have another scanf in line 5 which you have to replace too. Otherwise they each have their own buffers of the input and get mixed up.