链接: http://codeforces.com/contest/807
A
题意:太水了,按着题目要求写就行,分好情况。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include "stdio.h"
#include <stdio.h>
using namespace std;
int rating[1005][2];
int main() {
int n;
scanf("%d", &n);
int flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", &rating[i][0], &rating[i][1]);
if (rating[i][0] != rating[i][1]) flag = 1;
}
int i;
if (flag == 1) {
printf("rated\n");
}
else {
for (i = 0; i < n - 1; i++) {
if (rating[i][0] < rating[i + 1][0]) {
printf("unrated\n");
break;
}
}
if (i == n - 1) printf("maybe\n");
}
return 0;
}
C
题意:在OJ上,一个人AC了x道题目,提交了y道,所以目前AC率是x/y。求还需要提交多少题,才可以使AC率达到p/q。(要注意,如果x/y>p/q,需要提交错误的答案,以使分母变大。当然,即使x/y
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(){
int t;
long long x, y, p, q;
scanf("%d", &t);
while (t--){
scanf("%I64d%I64d%I64d%I64d", &x, &y, &p, &q);
if (p == 0){
if (x == 0) printf("0\n");
else printf("-1\n");
continue;
}
if (p == 1 && q == 1 && x != y){
printf("-1\n");
continue;
}
/*if (x*q < y*p){ //这里是错误的,即使x*q<y*p,也不一定只交正确提交就能达到p/q。
printf("%I64d\n", (q*x - p*y) / (p - q));
}*/
if (x*q == y*p){
printf("0\n");
}
else{ //这一步是重点,需要推导
long long h1 = ceil(x*1.0 / p); //因为涉及除法,有可能会产生精度问题。
//ceil意思是天花板,所以是向上取整。floor意思是地板,所以是向下取整。
long long h2 = ceil(y*1.0 / q);
long long h3 = ceil((y - x)*1.0 / (q - p));
long long k = max(h1, max(h2, h3)); //k为同时满足三个条件的最小值
printf("%I64d\n", k*q - y);
}
}
return 0;
}