poj2017
纯水题。。。。我只是vjudge登不上了才来做的
#include <iostream>
#include <cstdio>
using namespace std;
const int MaxN = 13;
int s[MaxN], t[MaxN];
int ans, n;
int main()
{
while(~scanf("%d", &n) && n!= -1){
s[0] = t[0] = ans = 0;
for(int i=1; i<=n; ++i){
scanf("%d%d", &s[i], &t[i]);
ans += s[i] * (t[i] - t[i - 1]);
}
printf("%d miles\n", ans);
}
return 0;
}
poj 2000
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n) && n){
int d = 1, ans = 0;
int i = 1;
for(i=1; i<=n; i+=d){
ans += d*d;
d += 1;
}
i -= d;
ans += d * (n - i);
printf("%d %d\n", n, ans);
}
return 0;
}
poj 1046
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int MaxN = 17;
struct rgb{
int r, g, b;
};
rgb a[MaxN];
int cacd(const rgb& a, const rgb& b);
int main()
{
for(int i=0; i<16; ++i){
scanf("%d%d%d", &a[i].r, &a[i].g, &a[i].b);
}
rgb temp;
while(scanf("%d%d%d", &temp.r, &temp.g, &temp.b) && temp.r > -1){
int ans = 0, d = cacd(temp, a[0]);
for(int i=0; i<16; ++i){
int td = cacd(temp, a[i]);
if(td < d){
d = td;
ans = i;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n", temp.r, temp.g, temp.b, a[ans].r, a[ans].g, a[ans].b);
}
return 0;
}
int cacd(const rgb& a, const rgb& b)
{
return ((b.r - a.r) * (b.r - a.r) + (b.g - a.g) * (b.g - a.g) + (b.b - a.b) * (b.b - a.b));
}
poj 1003
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps = 1e-8;
int main()
{
double l;
while(scanf("%lf", &l) && fabs(l) > eps){
double rl = 0.5;
int i = 2;
while(rl < l){
++i;
rl += 1.0 / i;
}
printf("%d card(s)\n", i - 1);
}
return 0;
}
poj 1004 1005