Add material for 2014 (day 1, mostly junior)

parent 38910a0c
#include <cstdio>
#include <cmath>
#include <cfloat>
using namespace std;
int main ()
{
#ifdef CONTEST
freopen("242b.in", "rt", stdin);
freopen("242b.out", "wt", stdout);
#endif
int n;
scanf("%d", &n);
int a[n], b[n];
int min_a = 0, max_b = 0;
int best_i;
for(int i = 0; i < n; i++)
{
scanf("%d %d", &a[i], &b[i]);
if(max_b - min_a <= b[i] - a[i])
{
max_b = b[i];
min_a = a[i];
best_i = i + 1;
}
}
for(int i = 0; i < n; i++)
{
if(a[i] < min_a || b[i] > max_b)
{
printf("-1\n");
return 0;
}
}
printf("%d\n", best_i);
return 0;
}
#include <cstdio>
#include <cmath>
#include <cfloat>
using namespace std;
int main ()
{
#ifdef CONTEST
freopen("281b.in", "rt", stdin);
freopen("281b.out", "wt", stdout);
#endif
int x, y, n;
scanf("%d %d %d", &x, &y, &n);
double min_d = DBL_MAX; // +infinity
int best_a, best_b;
for (int b=1; b<=n; b++) {
int a = (int) ceil((double) b*x/y - 0.5);
double d = fabs((double) x/y - (double) a/b);
if (d < min_d) {
min_d = d;
best_a = a;
best_b = b;
}
}
printf("%d/%d\n", best_a, best_b);
return 0;
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment