数学問(?)
自然とmathばっかり解いてた(しかも少ない←
英単語覚えるべき量が多くて厳しい
1401
とりあえずなんか数字の後ろの0の数数える奴。
5の倍数で割っていく数学的な解決法を用いる。
#include <cstdio> typedef long long ll; int main() { int t; scanf("%d",&t); for (int ix=0; ix<t; ix++) { ll n; scanf("%lld",&n); ll five=5; ll res=0; while (five<=n) { res+=n/five; five*=5; } printf("%lld\n",res); } }
2242
与えられた三点を通る円の円周を求める問題。
つまり三点からなる三角形の外接円の半径をみちびけばいいので、ぐぐって(ry
#include <cstdio> #include <cmath> #define pi 3.141592653589793 double line(double a, double b, double c, double d) { return sqrt((a-c)*(a-c)+(b-d)*(b-d)); } int main() { double x1, y1, x2, y2, x3, y3; while (scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF) { double a=line(x1,y1,x2,y2); double b=line(x2,y2,x3,y3); double c=line(x3,y3,x1,y1); double r=a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)); printf("%.2f\n",2*r*pi); } }
1775
x!をいくつかたしあわせてnが作れるか。
10!>1000000>9!より9!までを計算すればいいので前計算で全探索する。
0!を見逃して大量WA。
#include <cstdio> typedef long long ll; bool res[1000001]; int main() { res[0]=1; int f=1; for (int i=0; i<10; i++) { if (i) f*=i; for (int i=1000000-f; i>=0; i--) if (res[i]) res[i+f]=1; } res[0]=0; int n; while (scanf("%d",&n)) { if (n<0) break; if (res[n]) puts("YES"); else puts("NO"); } }