├── README.md ├── hihocoder ├── 1032 │ └── description.md └── 1033 │ └── description.md ├── poj-cpp ├── 1000 │ ├── 14323055_AC_0MS_148K.c │ ├── 13564208_AC_0MS_132K.c │ └── 16285493_AC_0MS_372K.cc ├── 1001 │ ├── 15091689_WA.java │ └── 15091735_AC_141MS_3424K.java ├── 1003 │ ├── 13711096_PE.cpp │ └── 13711097_AC_0MS_148K.cpp ├── 1004 │ └── 13711057_AC_0MS_148K.cpp ├── 1005 │ └── 13715971_AC_0MS_148K.cpp ├── 1006 │ └── 13715705_AC_719MS_132K.cpp ├── 1012 │ ├── 13890527_TLE.cpp │ └── 13890532_TLE.cpp ├── 1045 │ ├── 14649736_WA.cc │ └── 14649675_AC_0MS_404K.cc ├── 1050 │ └── 13827328_WA.c ├── 1061 │ ├── 13724980_TLE.cpp │ ├── 13724982_TLE.cpp │ ├── 13870638_WA.c │ ├── 13870667_CE.c │ ├── 13870642_TLE.c │ ├── 13870670_TLE.c │ ├── 13870710_WA.c │ ├── 13873404_WA.c │ ├── 13873433_WA.c │ ├── 13873438_WA.c │ ├── 13873441_WA.c │ ├── 13873449_WA.cpp │ ├── 13873545_WA.cpp │ ├── 13873550_TLE.cpp │ ├── 13724987_WA.cpp │ ├── 13724988_WA.cpp │ ├── 13724989_WA.cpp │ ├── 13873403_WA.c │ └── 13873500_TLE.c ├── 1064 │ ├── 14720367_WA.cc │ ├── 14720369_WA.cc │ └── 14720370_WA.cc ├── 1067 │ └── 14675963_AC_16MS_352K.cc ├── 1083 │ ├── 14260736_WA.cc │ └── 14260843_WA.cc ├── 1157 │ ├── 14296012_WA.cc │ ├── 14296021_WA.cc │ ├── 14296239_AC_0MS_468K.cc │ └── 14296209_WA.cc ├── 1159 │ ├── 13975884_MLE.cpp │ ├── 13975886_MLE.cpp │ ├── 13975891_RE.cpp │ ├── 13975892_RE.cpp │ ├── 13975933_RE.cpp │ ├── 13975935_RE.cpp │ ├── 13975939_MLE.cpp │ ├── 13975959_MLE.c │ ├── 13975985_RE.c │ └── 13975987_AC_704MS_49168K.c ├── 1163 │ └── 13824911_AC_32MS_212K.c ├── 1183 │ ├── 14818746_WA.cc │ ├── 14818864_AC_32MS_352K.cc │ ├── 14818754_WA.cc │ └── 14818759_WA.cc ├── 1207 │ ├── 13860487_WA.cpp │ └── 13860812_WA.cpp ├── 1218 │ └── 13943396_AC_0MS_132K.c ├── 1316 │ └── 13997622_TLE.cpp ├── 1326 │ ├── 14771131_AC_0MS_356K.cc │ └── 14771129_WA.cc ├── 1338 │ └── 14819111_MLE.cc ├── 1401 │ └── 14264842_AC_344MS_356K.cc ├── 1423 │ ├── 14216226_TLE.cc │ ├── 14216277_WA.cc │ ├── 14216283_RE.cc │ ├── 14216288_MLE.cc │ ├── 14216290_MLE.cc │ ├── 14216294_RE.cc │ ├── 14216275_MLE.cc │ ├── 14216313_RE.cc │ └── 14216317_AC_672MS_39540K.cc ├── 1450 │ ├── 14923690_AC_79MS_364K.cc │ └── 14923685_WA.cc ├── 1455 │ └── 14785926_AC_0MS_548K.cc ├── 1488 │ └── 14865422_AC_16MS_336K.cc ├── 1517 │ ├── 14043421_WA.cpp │ └── 14043433_AC_0MS_152K.cpp ├── 1519 │ ├── 14264314_WA.cc │ └── 14264327_AC_0MS_356K.cc ├── 1528 │ └── 14795278_AC_0MS_628K.cc ├── 1543 │ ├── 14362395_WA.cpp │ └── 14362399_AC_16MS_132K.cpp ├── 1552 │ └── 14026391_AC_0MS_132K.cpp ├── 1565 │ └── 14564593_AC_16MS_356K.cc ├── 1656 │ └── 14559639_AC_0MS_412K.cc ├── 1658 │ └── 14054716_AC_16MS_148K.cpp ├── 1663 │ └── 14366244_AC_16MS_132K.cpp ├── 1664 │ ├── 13893063_AC_0MS_180K.cpp │ └── 13893064_AC_0MS_180K.cpp ├── 1665 │ └── 15091938_AC_0MS_404K.cc ├── 1731 │ ├── 14702045_AC_454MS_400K.cc │ ├── 14702052_PE.cc │ └── 14702054_AC_47MS_376K.cc ├── 1775 │ └── 14918263_TLE.cc ├── 1833 │ ├── 14245556_WA.cpp │ ├── 14245538_TLE.cc │ ├── 14245543_TLE.cpp │ ├── 14245636_WA.cpp │ └── 14245873_AC_469MS_136K.cpp ├── 1836 │ ├── 14907018_WA.cc │ ├── 14907022_WA.cc │ └── 14907037_WA.cc ├── 1837 │ └── 14402377_AC_141MS_1668K.cc ├── 1844 │ └── 14371588_AC_0MS_132K.cpp ├── 1852 │ └── 14871055_AC_141MS_356K.cc ├── 1862 │ ├── 14179241_AC_0MS_168K.cpp │ └── 14710605_AC_32MS_612K.cc ├── 1922 │ ├── 14299050_WA.c │ ├── 14299014_WA.c │ ├── 14299043_WA.cpp │ ├── 14299048_WA.cc │ ├── 14299054_AC_16MS_168K.c │ ├── 14299031_AC_16MS_168K.c │ └── 14299033_AC_16MS_168K.c ├── 1936 │ └── 13972730_AC_16MS_448K.cpp ├── 1953 │ └── 14312773_AC_0MS_148K.cpp ├── 1969 │ └── 14723833_AC_0MS_356K.cc ├── 2000 │ └── 13954845_AC_16MS_160K.cpp ├── 2013 │ ├── 14318554_WA.cpp │ └── 14318563_AC_0MS_148K.cpp ├── 2017 │ ├── 13967961_CE.cpp │ ├── 13967918_AC_0MS_156K.cpp │ └── 13967962_AC_16MS_156K.cpp ├── 2027 │ └── 13892858_AC_0MS_180K.cpp ├── 2081 │ └── 14105833_AC_2391MS_19140K.cpp ├── 2104 │ ├── 13944119_TLE.cc │ ├── 13943750_WA.cpp │ ├── 13943990_WA.cpp │ ├── 13944005_TLE.cpp │ ├── 13944114_WA.cc │ └── 13944073_TLE.cpp ├── 2105 │ └── 14026668_AC_0MS_132K.cpp ├── 2109 │ ├── 14073192_AC_0MS_180K.c │ └── 14073190_WA.c ├── 2140 │ └── 14090094_AC_610MS_356K.cc ├── 2141 │ ├── 14554775_WA.cc │ ├── 14554787_WA.cc │ └── 14554799_AC_16MS_348K.cc ├── 2181 │ ├── 14815963_WA.cc │ └── 14816531_AC_63MS_1476K.cc ├── 2196 │ ├── 14684699_WA.cc │ ├── 14684691_WA.cc │ └── 14684700_AC_0MS_340K.cc ├── 2209 │ └── 14912697_AC_32MS_356K.cc ├── 2229 │ ├── 14153188_AC_125MS_4068K.cpp │ ├── 14152345_RE.cpp │ └── 14153166_RE.cpp ├── 2231 │ ├── 14699435_TLE.cc │ └── 14699438_AC_985MS_432K.cc ├── 2234 │ └── 14742228_AC_0MS_384K.cc ├── 2244 │ ├── 14384433_AC_79MS_156K.cpp │ └── 14384426_CE.cpp ├── 2249 │ └── 14708576_WA.cc ├── 2291 │ └── 14900274_AC_0MS_364K.cc ├── 2299 │ └── 13759727_TLE.cpp ├── 2301 │ └── 14260737_AC_0MS_356K.cc ├── 2309 │ └── 14711108_AC_0MS_396K.cc ├── 2350 │ └── 14299905_AC_16MS_172K.cpp ├── 2352 │ └── 13943261_TLE.c ├── 2371 │ ├── 14714908_RE.cc │ ├── 14714910_RE.cc │ └── 14714914_AC_47MS_784K.cc ├── 2387 │ ├── 14392052_WA.cc │ └── 14392069_AC_16MS_432K.cc ├── 2388 │ └── 13860498_AC_16MS_176K.cpp ├── 2390 │ └── 14225293_AC_47MS_396K.cc ├── 2407 │ └── 14712803_AC_0MS_396K.cc ├── 2411 │ └── 14600605_TLE.cc ├── 2418 │ ├── 14298411_AC_1485MS_352K.cpp │ ├── 14298400_WA.cc │ └── 14298402_WA.cpp ├── 2453 │ └── 14764672_AC_0MS_388K.cc ├── 2470 │ └── 14886888_AC_266MS_716K.cc ├── 2478 │ ├── 14798051_WA.cc │ ├── 14798123_WA.cc │ ├── 14798158_WA.cc │ ├── 14798276_WA.cc │ └── 14798296_AC_110MS_12156K.cc ├── 2503 │ └── 13929195_AC_844MS_10488K.cpp ├── 2509 │ └── 14345498_AC_0MS_356K.cc ├── 2513 │ └── 14089319_TLE.cpp ├── 2521 │ └── 14598751_AC_0MS_356K.cc ├── 2533 │ ├── 14339630_AC_0MS_356K.cc │ ├── 13968019_AC_0MS_176K.cpp │ ├── 13929209_AC_0MS_192K.cpp │ ├── 13937753_AC_32MS_144K.cpp │ ├── 13927940_WA.cpp │ ├── 13927884_WA.cpp │ ├── 13927896_WA.cpp │ ├── 13927916_WA.cpp │ ├── 13923581_WA.cpp │ ├── 13923608_WA.cpp │ └── 13923613_WA.cpp ├── 2538 │ ├── 14872447_WA.cc │ ├── 14872457_WA.cc │ └── 14872463_AC_16MS_316K.cc ├── 2551 │ └── 14244955_AC_0MS_356K.cc ├── 2575 │ ├── 14766023_WA.cc │ └── 14766024_WA.cc ├── 2578 │ └── 14340860_AC_0MS_132K.cpp ├── 2583 │ └── 14792642_AC_0MS_356K.cc ├── 2591 │ └── 14819113_MLE.cc ├── 2602 │ ├── 14333990_TLE.c │ ├── 14333986_TLE.cpp │ ├── 14333994_TLE.c │ ├── 14333996_WA.c │ ├── 14333982_TLE.cpp │ ├── 14334009_WA.c │ ├── 14334012_WA.c │ ├── 14334020_AC_1500MS_1136K.c │ ├── 14334021_AC_469MS_1360K.cc │ ├── 14334024_AC_454MS_1360K.cc │ └── 14333999_WA.c ├── 2608 │ └── 14795358_AC_0MS_356K.cc ├── 2623 │ ├── 14819455_WA.cc │ ├── 14819461_WA.cc │ ├── 14819471_WA.cc │ └── 14819477_AC_250MS_2312K.cc ├── 2624 │ └── 14514241_WA.cpp ├── 2636 │ ├── 14297661_AC_16MS_156K.c │ ├── 14297641_CE.cc │ └── 14297648_CE.cc ├── 2656 │ └── 14258359_AC_0MS_356K.cc ├── 2663 │ └── 14817338_TLE.cc ├── 2707 │ └── 14806182_AC_0MS_404K.cc ├── 2719 │ └── 14684513_AC_141MS_356K.cc ├── 2828 │ └── 14321324_TLE.cpp ├── 2840 │ ├── 14366361_WA.cpp │ └── 14366415_AC_0MS_132K.cpp ├── 2853 │ └── 14795473_AC_0MS_356K.cc ├── 2871 │ ├── 14734699_WA.cc │ ├── 14734701_WA.cc │ └── 14734703_AC_0MS_372K.cc ├── 2909 │ └── 14555048_AC_0MS_760K.cc ├── 2924 │ └── 14826064_AC_0MS_356K.cc ├── 3030 │ └── 14098714_AC_0MS_152K.cpp ├── 3062 │ ├── 14124978_OLE.c │ ├── 14125020_OLE.c │ ├── 14124965_OLE.c │ ├── 14124949_OLE.c │ ├── 14124951_PE.c │ ├── 14124987_RE.c │ ├── 14125003_AC_0MS_96K.c │ ├── 14124953_OLE.c │ └── 14124955_PE.c ├── 3077 │ └── 14699360_AC_0MS_396K.cc ├── 3085 │ └── 14715355_AC_0MS_356K.cc ├── 3086 │ └── 14699361_AC_0MS_396K.cc ├── 3093 │ └── 13929222_WA.cpp ├── 3094 │ └── 14027811_AC_0MS_128K.cpp ├── 3100 │ ├── 14366722_AC_0MS_388K.cc │ ├── 14366669_CE.cpp │ └── 14366674_AC_0MS_384K.cc ├── 3117 │ ├── 14779402_WA.cc │ └── 14779415_AC_0MS_356K.cc ├── 3176 │ ├── 14057550_AC_63MS_696K.cpp │ └── 14057552_AC_32MS_696K.cpp ├── 3181 │ └── 14210927_WA.cpp ├── 3185 │ └── 15003606_WA.cc ├── 3210 │ └── 14718972_AC_0MS_356K.cc ├── 3224 │ └── 14764588_AC_16MS_388K.cc ├── 3250 │ ├── 14785453_WA.cc │ ├── 14785461_WA.cc │ └── 14785468_AC_172MS_672K.cc ├── 3253 │ ├── 14043744_WA.cpp │ ├── 14043811_WA.cpp │ ├── 13917281_WA.cpp │ └── 13917288_AC_32MS_356K.cpp ├── 3277 │ └── 14766051_WA.cc ├── 3299 │ ├── 13724837_CE.c │ ├── 13724839_WA.cpp │ ├── 13724861_WA.c │ ├── 13724849_WA.cpp │ └── 13724866_WA.c ├── 3320 │ └── 14159886_WA.cpp ├── 3325 │ └── 14699344_AC_0MS_396K.cc ├── 3356 │ ├── 14827221_WA.cc │ └── 14827226_AC_0MS_4376K.cc ├── 3372 │ ├── 14885889_WA.cc │ └── 14885913_AC_16MS_352K.cc ├── 3438 │ └── 14478174_AC_1094MS_376K.cc ├── 3507 │ ├── 14820996_WA.cc │ ├── 14821002_WA.cc │ └── 14821005_WA.cc ├── 3589 │ └── 14253716_AC_0MS_160K.cpp ├── 3617 │ └── 14541935_PE.cpp ├── 3619 │ └── 14813824_AC_47MS_356K.cc ├── 3624 │ ├── 13967980_RE.cpp │ ├── 13967984_AC_297MS_568K.cpp │ └── 14718840_AC_266MS_440K.cc ├── 3627 │ ├── 14814057_RE.cc │ └── 14814334_AC_32MS_428K.cc ├── 3628 │ └── 14829344_AC_172MS_356K.cc ├── 3632 │ └── 14712962_AC_0MS_400K.cc ├── 3637 │ └── 14891874_AC_94MS_428K.cc ├── 3650 │ └── 14678748_AC_0MS_340K.cc ├── 3663 │ └── 14734761_AC_47MS_436K.cc ├── 3673 │ ├── 14090192_WA.cc │ ├── 14090198_WA.c │ ├── 14090204_AC_0MS_132K.c │ └── 14090207_AC_0MS_132K.c ├── 3748 │ └── 14881822_AC_0MS_356K.cc ├── 3749 │ └── 14678715_AC_0MS_332K.cc ├── 3751 │ └── 14865453_AC_0MS_356K.cc ├── 3800 │ └── 14908262_AC_0MS_-784K.c ├── 3903 │ ├── 13929317_AC_63MS_1932K.cpp │ └── 13929229_WA.cpp ├── 3979 │ └── 14773545_AC_0MS_356K.cc ├── 3980 │ ├── 14323047_WA.c │ ├── 14256915_CE.cc │ ├── 14256917_OLE.c │ ├── 14323048_AC_110MS_148K.c │ └── 14256920_AC_125MS_160K.c ├── 3981 │ └── 14723653_AC_0MS_336K.cc ├── 3983 │ └── 14181454_AC_0MS_120K.c ├── 1000 A+B Problem │ ├── description.md │ └── main.cpp ├── 1004 Financial Management │ ├── description.md │ └── main.cpp ├── 1005 I Think I Need a Houseboat │ ├── description.md │ └── main.cpp ├── 1001 Exponentiation │ └── description.md ├── 1003 Hangover │ ├── description.md │ └── main.cpp └── 1006 Biorhythms │ ├── description.md │ └── main.cpp └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # 算法之路 2 | -------------------------------------------------------------------------------- /hihocoder/1033/description.md: -------------------------------------------------------------------------------- 1 | # 数位 dp -------------------------------------------------------------------------------- /poj-cpp/3800/14908262_AC_0MS_-784K.c: -------------------------------------------------------------------------------- 1 | main(){} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | a.out 2 | .idea 3 | cmake-build-debug 4 | -------------------------------------------------------------------------------- /poj-cpp/3062/14124978_OLE.c: -------------------------------------------------------------------------------- 1 | main(){while(putchar(getchar()));} -------------------------------------------------------------------------------- /poj-cpp/3062/14125020_OLE.c: -------------------------------------------------------------------------------- 1 | main(){for(;~putchar(getchar()););} -------------------------------------------------------------------------------- /poj-cpp/3983/14181454_AC_0MS_120K.c: -------------------------------------------------------------------------------- 1 | main(){puts("5*(5-(1/5))");} -------------------------------------------------------------------------------- /hihocoder/1032/description.md: -------------------------------------------------------------------------------- 1 | # 最长回文子串 2 | 3 | 求字符串的最长回文串 4 | 5 | -------------------------------------------------------------------------------- /poj-cpp/1000 A+B Problem/description.md: -------------------------------------------------------------------------------- 1 | # A + B 2 | 3 | 计算两个整数a和b的和。 4 | -------------------------------------------------------------------------------- /poj-cpp/3062/14124965_OLE.c: -------------------------------------------------------------------------------- 1 | main(){char str[1024];for(;~gets(str);puts(str));} -------------------------------------------------------------------------------- /poj-cpp/3062/14124949_OLE.c: -------------------------------------------------------------------------------- 1 | main(){char str[1024];for(;scanf("%s",str);puts(str));} -------------------------------------------------------------------------------- /poj-cpp/3062/14124951_PE.c: -------------------------------------------------------------------------------- 1 | main(){char str[1024];for(;~scanf("%s",str);puts(str));} -------------------------------------------------------------------------------- /poj-cpp/3062/14124987_RE.c: -------------------------------------------------------------------------------- 1 | main(){char c;for(;~scanf("%c",c);putchar(c));} 2 | -------------------------------------------------------------------------------- /poj-cpp/3062/14125003_AC_0MS_96K.c: -------------------------------------------------------------------------------- 1 | main(){int c;for(;-1!=(c=getchar());putchar(c));} -------------------------------------------------------------------------------- /poj-cpp/3980/14323047_WA.c: -------------------------------------------------------------------------------- 1 | main(a,b){for(;~scanf("%d%d",&a,&b);printf("%d\n",a+b));} -------------------------------------------------------------------------------- /poj-cpp/1000/14323055_AC_0MS_148K.c: -------------------------------------------------------------------------------- 1 | main(a,b){scanf("%d%d",&a,&b);printf("%d\n",a+b);} -------------------------------------------------------------------------------- /poj-cpp/3980/14256915_CE.cc: -------------------------------------------------------------------------------- 1 | main(){int a,b;for(;scanf("%d%d",&a,&b);printf("%d\n",a%b));} -------------------------------------------------------------------------------- /poj-cpp/3980/14256917_OLE.c: -------------------------------------------------------------------------------- 1 | main(){int a,b;for(;scanf("%d%d",&a,&b);printf("%d\n",a%b));} -------------------------------------------------------------------------------- /poj-cpp/3062/14124953_OLE.c: -------------------------------------------------------------------------------- 1 | main(){char str[1024];for(;scanf("%s", str);printf("%s",str));} 2 | -------------------------------------------------------------------------------- /poj-cpp/3062/14124955_PE.c: -------------------------------------------------------------------------------- 1 | main(){char str[1024];for(;~scanf("%s", str);printf("%s",str));} 2 | -------------------------------------------------------------------------------- /poj-cpp/3980/14323048_AC_110MS_148K.c: -------------------------------------------------------------------------------- 1 | main(a,b){for(;~scanf("%d%d",&a,&b);printf("%d\n",a%b));} -------------------------------------------------------------------------------- /poj-cpp/3980/14256920_AC_125MS_160K.c: -------------------------------------------------------------------------------- 1 | main(){int a,b;for(;~scanf("%d%d",&a,&b);printf("%d\n",a%b));} -------------------------------------------------------------------------------- /poj-cpp/1000/13564208_AC_0MS_132K.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int a, b; 5 | scanf("%d%d", &a, &b); 6 | printf("%d", a+b); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /poj-cpp/1000/16285493_AC_0MS_372K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b; 6 | scanf("%d %d",&a, &b); 7 | printf("%d\n",a+b); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /poj-cpp/1000 A+B Problem/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a, b; 6 | 7 | scanf("%d%d", &a, &b); 8 | printf("%d\n", a + b); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /poj-cpp/1004 Financial Management/description.md: -------------------------------------------------------------------------------- 1 | # Financial Management 2 | 3 | Larry 找到了一个工作,年底了要计算一下工资的平均数。 4 | 5 | 求12个数的平均数。 6 | 7 | 输出保留两位小数,并且前面一个 $ 符号 8 | 9 | Tips: G++ 提交注意输出 double 类型的变量要用 %f 而不是 %lf 10 | 11 | -------------------------------------------------------------------------------- /poj-cpp/1005 I Think I Need a Houseboat/description.md: -------------------------------------------------------------------------------- 1 | # I Think I Need a Houseboat 2 | 3 | 说有个人啊,住在一个小岛上的某个位置 P ,坐标是 (x, y) ,然后有一天,小岛的中心 (0, 0) 位置开始以一个半圆的形状像这人住的方向开始腐蚀了,并且速度是每年 50 平方米,他想知道他还能在这住多少年? 4 | 5 | 输入数据不会发生他正好住在某年的边界上这种情况。 6 | 7 | -------------------------------------------------------------------------------- /poj-cpp/1004 Financial Management/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double mon, sum = 0; 6 | 7 | while(~scanf("%lf", &mon)) 8 | sum += mon; 9 | printf("$%.2f", sum / 12); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /poj-cpp/1001 Exponentiation/description.md: -------------------------------------------------------------------------------- 1 | # Exponentiation 2 | 3 | 题意很简单,计算 a 的 n 次方 4 | 5 | a 可以是小数,n 不会超过 25,总之 double 存不下就是了,显然一道挺麻烦的高精度的题 6 | 7 | 需要注意的有以下两点: 8 | 9 | 结尾不要有多余的 0,比如: 1.23400 要输出 1.234 10 | 11 | 结果小于 1 不要输出前面的 0,比如: 0.001 要输出 .001 12 | 13 | -------------------------------------------------------------------------------- /poj-cpp/2181/14815963_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, n, ans = 0; 6 | scanf("%d", &N); 7 | for(int i=1; i<=N; i++) { 8 | scanf("%d", &n); 9 | if(i%2) ans += n; 10 | } 11 | printf("%d\n", ans); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /poj-cpp/2109/14073192_AC_0MS_180K.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double n, p; 7 | 8 | while(~scanf("%lf%lf", &n, &p)) { 9 | printf("%lg\n", pow(p, 1/n)); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /poj-cpp/3210/14718972_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | 7 | while(scanf("%d", &n) && n) { 8 | if(n&1) printf("%d\n", n-1); 9 | else printf("No Solution!\n"); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /poj-cpp/2027/13892858_AC_0MS_180K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int Q, a, b; 5 | scanf("%d", &Q); 6 | while(Q--){ 7 | scanf("%d%d", &a, &b); 8 | if(a 2 | 3 | int main() 4 | { 5 | int R, Y; 6 | double M; 7 | 8 | scanf("%d%lf%d", &R, &M, &Y); 9 | while(Y--) M *= (1+R/100.0); 10 | printf("%d\n", (int)M); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /poj-cpp/2521/14598751_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a, b, c, d; 6 | 7 | while(scanf("%d%d%d%d", &a, &b, &c, &d)) { 8 | if(!a && !b && !c && !d) break; 9 | printf("%d\n", c-b+a); 10 | } 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /poj-cpp/2109/14073190_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double n, p; 7 | 8 | while(~scanf("%lf%lf", &n, &p)) { 9 | printf("%d\n", (int)pow(p, 1/n)); 10 | } 11 | 12 | // printf("%lld", ); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /poj-cpp/1003 Hangover/description.md: -------------------------------------------------------------------------------- 1 | # Hangover 2 | 3 | 一张卡片平放在一个平台上,可以把牌的一部分悬在平台外面(另一部分在平台上),并且保证牌不会掉下去。 4 | 5 | 如果只有一张牌的话,突出平台的部分最多是 1/2 。 6 | 7 | 如果只有两张牌的话,突出平台的部分最多是 1/2 + 1/3 。 8 | 9 | 如果只有三张牌的话,突出平台的部分最多是 1/2 + 1/3 + 1/4 。 10 | 11 | ... 12 | 13 | 给你一个数,你来判断最少要多少张牌才能使突出平台的部分达到这么大。 14 | 15 | 由于给定的数小于 5.20 ,所以直接暴力即可。 16 | 17 | -------------------------------------------------------------------------------- /poj-cpp/2636/14297661_AC_16MS_156K.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, N, T, sum, n; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d", &N); 10 | sum = 0; 11 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int r, x, y; 6 | scanf("%x,%d,%d", &r, &x, &y); 7 | if(r&1< 2 | 3 | int main() 4 | { 5 | double d; 6 | 7 | while(scanf("%lf", &d) && d > 0.001) { 8 | int n = 2; 9 | double s = 0; 10 | while(s < d) 11 | s += 1.0 / n++; 12 | printf("%d card(s)\n", n - 2); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1844/14371588_AC_0MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, S, sum; 6 | 7 | scanf("%d", &S); 8 | for(i=1, sum=0; ; i++) { 9 | sum += i; 10 | if(sum>=S && (sum-S)%2==0) break; 11 | } 12 | printf("%d\n", i); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /poj-cpp/3507/14820996_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a, b, c, d, e, f; 6 | 7 | while(scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f)) { 8 | if(!a && !b && !c && !d && !e && !f) break; 9 | printf("%g\n", (a+b+c+d+e+f)/6.0); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /poj-cpp/1401/14264842_AC_344MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T, n, sum; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d", &n); 10 | for(sum=0; n/5; n/=5) sum += n/5; 11 | printf("%d\n", sum); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /poj-cpp/2388/13860498_AC_16MS_176K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int num[1100000]; 7 | 8 | int main(){ 9 | int n, i; 10 | while(~scanf("%d", &n)){ 11 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int sum, i, N锛孴, n锛� scanf("%d", &T); 6 | while(T--) { 7 | scanf("%d", &N); 8 | sum = 0; 9 | for(i=0; i 2 | 3 | int main() 4 | { 5 | double p, q; 6 | 7 | scanf("%lf", &p); 8 | while(scanf("%lf", &q)) { 9 | if(p==999) break; 10 | printf("%lg\n", q-p); 11 | p = q; 12 | } 13 | printf("End of Output\n"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/2871/14734701_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double p, q; 6 | 7 | scanf("%lf", &p); 8 | while(scanf("%lf", &q)) { 9 | if(q==999) break; 10 | printf("%lg\n", q-p); 11 | p = q; 12 | } 13 | printf("End of Output\n"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/3372/14885889_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, i; 6 | 7 | while(~scanf("%d", &N)) { 8 | for(i=0; 1< 2 | 3 | int main() 4 | { 5 | int sum, i, N锛孴, n; 6 | scanf("%d", &T); 7 | while(T--) { 8 | scanf("%d", &N); 9 | sum = 0; 10 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int N, i; 6 | 7 | while(~scanf("%d", &N)) { 8 | for(i=0; 1< 2 | 3 | 4 | int main() 5 | { 6 | char maps[27]; 7 | scanf("%s", maps); 8 | int ch; 9 | getchar(); 10 | while((ch=getchar())!=EOF) { 11 | if(ch==' ') putchar(' '); 12 | else if(ch<='Z' && ch>'A') { 13 | putchar(maps[ch-'A']-'a'+'A'); 14 | } else { 15 | putchar(maps[ch-'a']); 16 | } 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /poj-cpp/2141/14554787_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | char maps[27]; 7 | scanf("%s", maps); 8 | int ch; 9 | getchar(); 10 | while((ch=getchar())!=EOF) { 11 | if(ch==' ') putchar(' '); 12 | else if(ch<='Z' && ch>='A') { 13 | putchar(maps[ch-'A']-'a'+'A'); 14 | } else { 15 | putchar(maps[ch-'a']); 16 | } 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /poj-cpp/2578/14340860_AC_0MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a, b, c; 6 | 7 | scanf("%d%d%d", &a, &b, &c); 8 | if(a<=168) printf("CRASH %d\n", a); 9 | else if(b<=168) printf("CRASH %d\n", b); 10 | else if(c<=168) printf("CRASH %d\n", c); 11 | else printf("NO CRASH"); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /poj-cpp/2871/14734703_AC_0MS_372K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double p, q; 6 | 7 | scanf("%lf", &p); 8 | while(scanf("%lf", &q)) { 9 | if(q==999) break; 10 | printf("%.2f\n", q-p); 11 | p = q; 12 | } 13 | printf("End of Output\n"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/3277/14766051_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | 5 | int main() 6 | { 7 | int N; 8 | ll a, b, h, ans = 0; 9 | scanf("%d", &N); 10 | while(N--) { 11 | scanf("%lld%lld%lld", &a, &b, &h); 12 | ans += (b-a)*h; 13 | } 14 | printf("%lld\n", ans-1); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /poj-cpp/1003/13711096_PE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i; 5 | double sum=0, n; 6 | while(scanf("%lf", &n)){ 7 | if(0==n) break; 8 | for(i=2; ; i++){ 9 | sum += 1/(double)i; 10 | if(sum>n) break; 11 | } 12 | printf("%dcard(s)\n", i-1); 13 | sum = 0; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1565/14564593_AC_16MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str[50]; 7 | 8 | while(scanf("%s", str)) { 9 | if(!strcmp(str, "0")) break; 10 | int l = strlen(str); 11 | int ans = 0; 12 | for(int i=0; i 2 | 3 | 4 | int main() 5 | { 6 | char maps[27]; 7 | scanf("%s", maps); 8 | int ch; 9 | getchar(); 10 | while((ch=getchar())!=EOF) { 11 | if(ch<='Z' && ch>='A') { 12 | putchar(maps[ch-'A']-'a'+'A'); 13 | } else if(ch<='z' && ch>='a') { 14 | putchar(maps[ch-'a']); 15 | } else 16 | putchar(ch); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /poj-cpp/2924/14826064_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | 4 | int main() 5 | { 6 | int T; 7 | ll s, a, b; 8 | scanf("%d", &T); 9 | for(int nC=1; nC<=T; nC++) { 10 | printf("Scenario #%d:\n", nC); 11 | scanf("%lld%lld", &a, &b); 12 | printf("%lld\n\n", (a+b)*(b-a+1)/2); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /poj-cpp/1003/13711097_AC_0MS_148K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i; 5 | double sum=0, n; 6 | while(scanf("%lf", &n)){ 7 | if(0==n) break; 8 | for(i=2; ; i++){ 9 | sum += 1/(double)i; 10 | if(sum>n) break; 11 | } 12 | printf("%d card(s)\n", i-1); 13 | sum = 0; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/2453/14764672_AC_0MS_388K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | 7 | while(~scanf("%d", &n) && n) { 8 | int a = n + (n&-n); 9 | int b = (a|n) - a; 10 | b &= b<<1; 11 | while(b && !(b&1)) b >>= 1; 12 | printf("%d\n", a+b); 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /poj-cpp/1543/14362395_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, i, j, k, l; 6 | 7 | scanf("%d", &N); 8 | for(i=1; i<=N; i++) 9 | for(j=1; j<=i; j++) 10 | for(k=j; k<=i; k++) 11 | for(l=k; l<=i; l++) 12 | if(i*i*i==j*j*j+k*k*k+l*l*l) 13 | printf("Cube = %d, Triple = (%d,%d,%d)\n", i, j, k, l); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1045/14649736_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double VS, R, C, omg; 5 | int N; 6 | 7 | int main() 8 | { 9 | scanf("%lf%lf%lf%d", &VS, &R, &C, &N); 10 | while(N--) { 11 | scanf("%lf", &omg); 12 | double ans = C*R*omg*VS/sqrt(1+(C*R*omg)*(C*R*omg)); 13 | printf("%.3lf\n", ans); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /poj-cpp/1543/14362399_AC_16MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, i, j, k, l; 6 | 7 | scanf("%d", &N); 8 | for(i=3; i<=N; i++) 9 | for(j=2; j<=i; j++) 10 | for(k=j; k<=i; k++) 11 | for(l=k; l<=i; l++) 12 | if(i*i*i==j*j*j+k*k*k+l*l*l) 13 | printf("Cube = %d, Triple = (%d,%d,%d)\n", i, j, k, l); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/2551/14244955_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, n, ans; 6 | 7 | while(~scanf("%d", &N)) { 8 | ans = n = 1; 9 | while(n%=N) { 10 | n = n*10+1; 11 | ans++; 12 | } 13 | printf("%d\n", ans); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /poj-cpp/1731/14702045_AC_454MS_400K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char str[201]; 8 | 9 | int main() 10 | { 11 | scanf("%s", &str); 12 | int l = strlen(str); 13 | sort(str, str+l); 14 | do { 15 | printf("%s\n", str); 16 | } while(next_permutation(str, str+l)); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/1922/14299050_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500.0/(v/3.6) + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | #include 3 | 4 | int arr[1100000]; 5 | 6 | int main() 7 | { 8 | int i, n; 9 | 10 | scanf("%d", &n); 11 | arr[1] = 1; 12 | for(i=2; i<=n; i++) { 13 | arr[i] = (arr[i-1] + (i%2?0:arr[i/2]))%1000000000; 14 | } 15 | printf("%d\n", arr[n]); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/1045/14649675_AC_0MS_404K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double VS, R, C, omg; 5 | int N; 6 | 7 | int main() 8 | { 9 | scanf("%lf%lf%lf%d", &VS, &R, &C, &N); 10 | while(N--) { 11 | scanf("%lf", &omg); 12 | double ans = C*R*omg*VS/sqrt(1+(C*R*omg)*(C*R*omg)); 13 | printf("%.3f\n", ans); 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /poj-cpp/1922/14299014_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500/(v/3.6) + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500/(v/3.6) + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500/(v/3.6) + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500*3.6/v + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int main() 4 | { 5 | int T, a, b; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d%d", &a, &b); 10 | if(a>=b && (a+b)%2==0) 11 | printf("%d %d\n", (a+b)/2, a-(a+b)/2); 12 | else printf("impossible\n"); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1922/14299031_AC_16MS_168K.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500.0*3.6/v + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int main() 4 | { 5 | int N, v, t, ans; 6 | double time; 7 | 8 | while(scanf("%d", &N) && N) { 9 | ans = 99999; 10 | while(N--) { 11 | scanf("%d%d", &v, &t); 12 | if(t<0) continue; 13 | time = 4500.0/v*3.6 + t; 14 | if(time-(int)time>0) time++; 15 | if((int)time 2 | 3 | int dp[50000]; 4 | 5 | int main() 6 | { 7 | dp[1] = dp[2] = 0; dp[3] = 1; 8 | for(int i=4; i<50000; i++) dp[i] = i-2 + dp[i-2]; 9 | int T; 10 | scanf("%d", &T); 11 | while(T--) { 12 | int n; 13 | scanf("%d", &n); 14 | printf("%d\n", dp[n]); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/3030/14098714_AC_0MS_152K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, a, b, c; 6 | 7 | scanf("%d", &N); 8 | while(N--) { 9 | scanf("%d%d%d", &a, &b, &c); 10 | if(a==b-c) puts("does not matter"); 11 | else if(a>b-c) puts("do not advertise"); 12 | else puts("advertise"); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1488/14865422_AC_16MS_336K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int ch, ok = 0; 6 | 7 | while(ch=getchar()) { 8 | if(ch==EOF) break; 9 | if(ch=='"') { 10 | if(ok==0) printf("``"); 11 | else printf("''"); 12 | ok ^= 1; 13 | } else putchar(ch); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /poj-cpp/2350/14299905_AC_16MS_172K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int arr[1024], N, i, sum, ans, T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d", &N); 10 | for(i=0, sum=0; i(double)sum/N) ans++; 17 | } 18 | printf("%.3lf%%\n", (double)ans*100/N); 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /poj-cpp/1004/13711057_AC_0MS_148K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | double sum, month; 5 | int t, i; 6 | while(scanf("%lf", &sum)!=EOF){ 7 | for(i=0; i<11; i++){ 8 | scanf("%lf", &month); 9 | sum += month; 10 | } 11 | sum /= 12; 12 | t = (int)(sum*100); 13 | sum = (double)t/100; 14 | printf("$%lg\n", sum); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /poj-cpp/1953/14312773_AC_0MS_148K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T, nCase, n, i, arr[45]; 6 | 7 | arr[0] = 1; arr[1] = 2; 8 | for(i=2; i<45; i++) arr[i] = arr[i-1]+arr[i-2]; 9 | scanf("%d", &T); 10 | for(nCase=1; nCase<=T; nCase++) { 11 | scanf("%d", &n); 12 | printf("Scenario #%d:\n%d\n\n", nCase, arr[n]); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /poj-cpp/1061/13724980_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int x, y, m, n, l; 5 | int cnt; 6 | 7 | while(scanf("%d%d%d%d%d", &x, &y, &m, &n, &l)!=EOF){ 8 | cnt = 0; 9 | while(x!=y){ 10 | x += m; 11 | if(x>=l) x%=l; 12 | y += n; 13 | if(y>=l) y%=l; 14 | cnt ++; 15 | } 16 | printf("%d\n", cnt); 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /poj-cpp/1067/14675963_AC_16MS_352K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const double d = (sqrt(5)+1)/2; 5 | 6 | int main() 7 | { 8 | int a, b, k; 9 | 10 | while(~scanf("%d%d", &a, &b)) { 11 | if(a>b) a^=b^=a^=b; 12 | k = b-a; 13 | if(a==(int)(d*k)) 14 | printf("0\n"); 15 | else printf("1\n"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/1731/14702052_PE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char str[201]; 8 | 9 | int main() 10 | { 11 | scanf("%s", &str); 12 | int l = strlen(str); 13 | sort(str, str+l); 14 | do { 15 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int cnt, T, N, t; 6 | char str[128]; 7 | 8 | while(scanf("%d%d", &T, &N) && T) { 9 | cnt = 0; 10 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int n, a, b; 6 | 7 | while(~scanf("%d", &n)) { 8 | scanf("%d", &a); 9 | for(int i=1; i 2 | 3 | int main() 4 | { 5 | int cnt, T, N, t; 6 | char str[128]; 7 | 8 | while(scanf("%d%d", &T, &N) && T) { 9 | cnt = 0; 10 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int num, n, T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d%d", &num, &n); 10 | int ans = 0; 11 | for(int i=2; i*(1+i)/2<=n; i++) { 12 | if(0==(n-i*(1+i)/2)%i) ans++; 13 | } 14 | printf("%d %d\n", num, ans); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/3438/14478174_AC_1094MS_376K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int cnt, n, T; 6 | 7 | scanf("%d", &T); 8 | getchar(); 9 | while(T--) { 10 | n = getchar(); 11 | cnt = 1; 12 | while(1) { 13 | int ch = getchar(); 14 | if(ch!=n) { 15 | printf("%d%c", cnt, n); 16 | n = ch; 17 | cnt = 1; 18 | } else { 19 | cnt ++; 20 | } 21 | if(ch=='\n') break; 22 | } 23 | printf("\n"); 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /poj-cpp/1006 Biorhythms/description.md: -------------------------------------------------------------------------------- 1 | # Biorhythms 2 | 3 | 人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同一天。对于每个周期,我们会给出从当前年份的第一天开始,到出现高峰的天数(不一定是第一次高峰出现的时间)。你的任务是给定一个从当年第一天开始数的天数,输出从给定时间开始(不包括给定时间)下一次三个高峰落在同一天的时间(距给定时间的天数)。例如:给定时间为10,下次出现三个高峰同天的时间是12,则输出2(注意这里不是3)。 4 | 5 | 采用以下格式: 6 | 7 | Case 1: the next triple peak occurs in 1234 days. 8 | 9 | 注意:即使结果是1天,也使用复数形式“days”。 10 | -------------------------------------------------------------------------------- /poj-cpp/2840/14366361_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int hour, minute, T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d:%d", &hour, &minute); 10 | if(minute!=0) printf("0\n"); 11 | else { 12 | if(hour>12) printf("%d\b", hour-12); 13 | else printf("%d\n", hour+12); 14 | } 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/1005 I Think I Need a Houseboat/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int T; 6 | double x, y; 7 | 8 | scanf("%d", &T); 9 | for(int nC = 1; nC <= T; nC++) { 10 | scanf("%lf%lf", &x, &y); 11 | double s = (x * x + y * y) * 3.1415926535; 12 | int ans = (s / 100) + 1; 13 | printf("Property %d: This property will begin eroding in year %d.\n", nC, ans); 14 | } 15 | printf("END OF OUTPUT."); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/2840/14366415_AC_0MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int hour, minute, T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d:%d", &hour, &minute); 10 | if(minute!=0) printf("0\n"); 11 | else { 12 | if(hour>12) printf("%d\n", hour-12); 13 | else printf("%d\n", hour+12); 14 | } 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/1006 Biorhythms/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int p, e, i, d, a, c = 1; 6 | 7 | while(scanf("%d%d%d%d", &p, &e, &i, &d) && p >= 0) { 8 | for(a = d + 1; ; a++) { 9 | if((a - p) % 23 == 0 && 10 | (a - e) % 28 == 0 && 11 | (a - i) % 33 == 0) 12 | break; 13 | } 14 | printf("Case %d: the next triple peak occurs in %d days.\n", c++, a - d); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/2196/14684699_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | for(int i=2992; i<10000; i++) { 7 | int n = i; 8 | int s = 0; 9 | while(n) { 10 | s += n%16; 11 | n /= 16; 12 | } 13 | int s1 = i%10 + (i/10)%10 + (i/100)%10 + i/1000; 14 | if(s==s1) printf("%d\n", i); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/1006/13715705_AC_719MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int p, e, i, d, day, nCase=0, t; 5 | while(scanf("%d%d%d%d", &p, &e, &i, &d)){ 6 | if(-1==p) break; 7 | for(day=1; day<=21252; day++){ 8 | t = day+d; 9 | if(0==(t-p)%23 && 0==(t-e)%28 && 0==(t-i)%33) 10 | break; 11 | } 12 | printf("Case %d: the next triple peak occurs in %d days.\n", ++nCase, day); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /poj-cpp/1183/14818746_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int INF = 0x3f3f3f3f; 5 | 6 | int main() 7 | { 8 | int a, b, c; 9 | 10 | scanf("%d", &a); 11 | for(b=1; ; b++) { 12 | if(a!=b && 0==(a*b+1)%(b-a)) { 13 | c = (a*b+1)/(b-a); 14 | if(c<0) continue; 15 | break; 16 | } 17 | } 18 | printf("%d\n", b+c); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /poj-cpp/2140/14090094_AC_610MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int i, j, N, cnt, t; 7 | 8 | scanf("%d", &N); 9 | cnt = 0; 10 | for(i=1; i<=N; i++) { 11 | for(j=i; j<=N; j++) { 12 | if((i+j)*(j-i+1)/2==N) cnt++; 13 | else if((i+j)*(j-i+1)/2>N) break; 14 | } 15 | } 16 | printf("%d\n", cnt); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/1183/14818864_AC_32MS_352K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int INF = 0x3f3f3f3f3f3f3f3f; 5 | 6 | int main() 7 | { 8 | long long a, m, n; 9 | 10 | while(~scanf("%lld", &a)) { 11 | for(m=a; ; m--) { 12 | if(0==(a*a+1)%m) 13 | break; 14 | } 15 | n = (a*a+1) / m; 16 | printf("%lld\n", 2*a+m+n); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/1517/14043421_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int jiecheng(int n); 4 | 5 | int main() 6 | { 7 | int n, i; 8 | double sum; 9 | 10 | printf("n e\n- -----------\n"); 11 | printf("0 1\n"); 12 | sum = 1; 13 | for(i=1; i<=9; i++) { 14 | sum += 1.0/jiecheng(i); 15 | printf("%d %.9lg\n", i, sum); 16 | } 17 | return 0; 18 | } 19 | 20 | int jiecheng(int n) 21 | { 22 | if(n==1) return 1; 23 | else return n*jiecheng(n-1); 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/1731/14702054_AC_47MS_376K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char str[201]; 8 | 9 | int main() 10 | { 11 | scanf("%s", &str); 12 | int l = strlen(str); 13 | sort(str, str+l); 14 | do { 15 | for(int i=0; i 2 | 3 | int per[100010], N; 4 | 5 | int main() 6 | { 7 | int i; 8 | 9 | while(scanf("%d", &N) && N) { 10 | for(i=1; i<=N; i++) 11 | scanf("%d", &per[i]); 12 | for(i=1; i<=N; i++) 13 | if(per[per[i]]!=i) break; 14 | if(i<=N) printf("not ambiguous\n"); 15 | else printf("ambiguous\n"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/2309/14711108_AC_0MS_396K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T; 9 | long long n; 10 | 11 | scanf("%d", &T); 12 | while(T--) { 13 | scanf("%lld", &n); 14 | int i; 15 | for(i=0; i<32; i++) 16 | if(n & (1< 2 | 3 | int jiecheng(int n); 4 | 5 | int main() 6 | { 7 | int n, i; 8 | double sum; 9 | 10 | printf("n e\n- -----------\n"); 11 | printf("0 1\n"); 12 | sum = 1; 13 | for(i=1; i<=9; i++) { 14 | sum += 1.0/jiecheng(i); 15 | printf("%d %.10lg\n", i, sum); 16 | } 17 | return 0; 18 | } 19 | 20 | int jiecheng(int n) 21 | { 22 | if(n==1) return 1; 23 | else return n*jiecheng(n-1); 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/2509/14345498_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int ans, N, k, butt; 6 | 7 | while(~scanf("%d%d", &N, &k)) { 8 | ans = 0; 9 | butt = 0; 10 | while(N>0) { 11 | ans += N; 12 | butt += N; 13 | N = butt/k; 14 | butt %= k; 15 | } 16 | printf("%d\n", ans); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2538/14872447_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char S1[39] = {"1234567890QWERTYUIOPASDFGHJKLZXCVBNM,."}; 4 | char S2[39] = {"234567890-WERTYUIOP[SDFGHJKL;XCVBNM,./"}; 5 | int maps[128]; 6 | 7 | int main() 8 | { 9 | for(int i=0; i<38; i++) 10 | maps[S2[i]] = i; 11 | while(int ch=getchar()) { 12 | if(EOF==ch) break; 13 | if(ch==' ' || ch=='\n') putchar(ch); 14 | else putchar(S1[maps[ch]]); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /poj-cpp/2623/14819455_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 250005; 7 | int arr[maxn], N; 8 | 9 | int main() 10 | { 11 | scanf("%d", &N); 12 | for(int i=0; i 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, M; 9 | 10 | int main() 11 | { 12 | int T; 13 | scanf("%d", &T); 14 | for(int nC=1; nC<=T; nC++) { 15 | scanf("%d%d", &N, &M); 16 | double ans = N*M; 17 | if(N*M&1) ans += 0.41; 18 | printf("Scenario #%d:\n%.2f\n\n", nC, ans); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/1665/15091938_AC_0MS_404K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const double pi = acos(-1.0); 5 | 6 | int main() 7 | { 8 | double d, t; 9 | int n, nC = 0; 10 | while(~scanf("%lf%d%lf", &d, &n, &t)) { 11 | if(!n) break; 12 | double c = d * pi; 13 | double s = c * n / (12 * 5280); 14 | double v = s * 3600 / t; 15 | printf("Trip #%d: %.2f %.2f\n", ++nC, s, v); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/2104/13944119_TLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr[200000], tmp[200000], N, i, Q, l, r, k; 9 | scanf("%d%d", &N, &Q); 10 | for(i=1; i<=N; i++){ 11 | scanf("%d", &arr[i]); 12 | } 13 | while(Q--){ 14 | scanf("%d%d%d", &l, &r, &k); 15 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 16 | sort(tmp+l, tmp+r+1); 17 | printf("%d\n", tmp[l+k-1]); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /poj-cpp/2196/14684691_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | for(int i=2992; i<10000; i++) { 9 | int n = i; 10 | int s = 0; 11 | while(n>0) { 12 | s += n%16; 13 | n /= 16; 14 | } 15 | int s1 = i%10 + (i/10)%10 + (i/100)%10 + i/1000; 16 | if(s==s1) printf("%d\n", i); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2244/14384433_AC_79MS_156K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int next[160], N; 4 | 5 | int main() 6 | { 7 | int m, i, j, t; 8 | 9 | while(~scanf("%d", &N) && N) { 10 | m = 1; 11 | while(m++) { 12 | for(i=1; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 250005; 7 | long long arr[maxn], N; 8 | 9 | int main() 10 | { 11 | scanf("%d", &N); 12 | for(int i=0; i 2 | 3 | int que[85000], N, top, cnt; 4 | 5 | int main() 6 | { 7 | int a, ans = 0; 8 | top = cnt = 0; 9 | scanf("%d", &N); 10 | while(N--) { 11 | scanf("%d", &a); 12 | while(cnt && que[top-1] 2 | 3 | int main() 4 | { 5 | int N, s, t, sum, b; 6 | 7 | while(scanf("%d", &N)){ 8 | if(N==-1) break; 9 | sum = 0; 10 | t = 0; 11 | while(N--){ 12 | scanf("%d%d", &s, &b); 13 | sum += s*(b-t); 14 | t = b; 15 | } 16 | printf("%d miles\n", sum); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /poj-cpp/2104/13943750_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr[110000], tmp[110000], N, i, Q, l, r, k; 9 | scanf("%d%d", &N, &Q); 10 | for(i=1; i<=N; i++){ 11 | scanf("%d", &arr[i]); 12 | } 13 | while(Q--){ 14 | scanf("%d%d%d", &l, &r, &k); 15 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 16 | sort(tmp+l, tmp+r); 17 | printf("%d\n", tmp[l+k-1]); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /poj-cpp/2104/13943990_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr[200000], tmp[200000], N, i, Q, l, r, k; 9 | scanf("%d%d", &N, &Q); 10 | for(i=1; i<=N; i++){ 11 | scanf("%d", &arr[i]); 12 | } 13 | while(Q--){ 14 | scanf("%d%d%d", &l, &r, &k); 15 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 16 | sort(tmp+l, tmp+r); 17 | printf("%d\n", tmp[l+k-1]); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /poj-cpp/2418/14298411_AC_1485MS_352K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | map mp; 10 | int cnt; 11 | char str[35]; 12 | 13 | cnt = 0; 14 | while(gets(str)) { 15 | if(str[0]=='\0') continue; 16 | cnt++; 17 | mp[str] ++; 18 | } 19 | 20 | map::iterator it; 21 | for(it=mp.begin(); it!=mp.end(); it++) { 22 | printf("%s %.4lf\n", it->first.c_str(), (double)it->second*100/cnt); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/3320/14159886_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int arr[1100000], N, i, ans, t; 5 | 6 | int main() 7 | { 8 | scanf("%d", &N); 9 | memset(arr, 0, sizeof(arr)); 10 | ans = 0; 11 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr[200000], tmp[200000], N, i, Q, l, r, k; 9 | scanf("%d%d", &N, &Q); 10 | for(i=1; i<=N; i++){ 11 | scanf("%d", &arr[i]); 12 | } 13 | while(Q--){ 14 | scanf("%d%d%d", &l, &r, &k); 15 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 16 | sort(tmp+l, tmp+r+1); 17 | printf("%d\n", tmp[l+k-1]); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /poj-cpp/2707/14806182_AC_0MS_404K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int L, R, l, r; 9 | 10 | while(scanf("%d%d%d%d", &L, &R, &l, &r)) { 11 | if(!L && !R && !l && !r) break; 12 | double d = min((double)l/L, (double)r/R); 13 | d = max(d, min((double)l/R, (double)r/L)); 14 | if(d>1) d = 1; 15 | printf("%d%%\n", (int)(d*100)); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/3250/14785461_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int que[85000], N, top, cnt; 4 | 5 | int main() 6 | { 7 | int a, ans = 0; 8 | top = cnt = 0; 9 | scanf("%d", &N); 10 | while(N--) { 11 | scanf("%d", &a); 12 | while(cnt && que[top-1]<=a) { 13 | top--; cnt--; 14 | } 15 | ans += cnt; 16 | que[top++] = a; cnt++; 17 | } 18 | printf("%d\n", ans); 19 | 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /poj-cpp/2244/14384426_CE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int next[160], N; 4 | 5 | int main() 6 | { 7 | int m, i, j, t; 8 | 9 | while(~scanf("%d", &N) && N) { 10 | m = 1; 11 | while(m++) { 12 | for(i=1; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr[30000], N, i, sum, rzt; 9 | 10 | scanf("%d", &N); 11 | sum = 0; 12 | for(i=0; i1; i--) rzt += (sum-=arr[i]); 19 | printf("%d\n", rzt); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /poj-cpp/1519/14264314_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, sum; 6 | 7 | while(scanf("%d", &n) && n) { 8 | while(n>9) { 9 | sum = 0; 10 | while(n/10) { 11 | sum += n%10; 12 | n /= 10; 13 | } 14 | n += sum; 15 | } 16 | printf("%d\n", n); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2017/13967918_AC_0MS_156K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, s, t, sum, b; 6 | 7 | while(scanf("%d", &N)){ 8 | if(N==-1) break; 9 | sum = 0; 10 | t = 0; 11 | while(N--){ 12 | scanf("%d%d", &s, &b); 13 | sum += s*(b-t); 14 | t = b; 15 | } 16 | printf("%d miles\n", sum); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2017/13967962_AC_16MS_156K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, s, t, sum, b; 6 | 7 | while(scanf("%d", &N)){ 8 | if(N==-1) break; 9 | sum = 0; 10 | t = 0; 11 | while(N--){ 12 | scanf("%d%d", &s, &b); 13 | sum += s*(b-t); 14 | t = b; 15 | } 16 | printf("%d miles\n", sum); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2418/14298400_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | map mp; 11 | int cnt; 12 | char str[35]; 13 | 14 | cnt = 0; 15 | while(gets(str)) { 16 | if(!isalpha(str[0])) continue; 17 | cnt++; 18 | mp[str] ++; 19 | } 20 | 21 | map::iterator it; 22 | for(it=mp.begin(); it!=mp.end(); it++) { 23 | printf("%s %.4f\n", it->first.c_str(), (double)it->second*100/cnt); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2418/14298402_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | map mp; 11 | int cnt; 12 | char str[35]; 13 | 14 | cnt = 0; 15 | while(gets(str)) { 16 | if(!isalpha(str[0])) continue; 17 | cnt++; 18 | mp[str] ++; 19 | } 20 | 21 | map::iterator it; 22 | for(it=mp.begin(); it!=mp.end(); it++) { 23 | printf("%s %.4lf\n", it->first.c_str(), (double)it->second*100/cnt); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/3077/14699360_AC_0MS_396K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int T, n; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d", &n); 13 | int mod = 10; 14 | while(n/mod) { 15 | n = (n+mod*5/10) / mod * mod; 16 | mod *= 10; 17 | } 18 | printf("%d\n", n); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/3085/14715355_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int T, n, a, b, c, d; 7 | 8 | scanf("%d", &T); 9 | for(int nC=1; nC<=T; nC++) { 10 | scanf("%d", &n); 11 | a = n/25; n %= 25; 12 | b = n/10; n %= 10; 13 | c = n/5; n %= 5; 14 | d = n; 15 | printf("%d %d QUARTER(S), %d DIME(S), %d NICKEL(S), %d PENNY(S)\n", nC, a, b, c, d); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/3299/13724837_CE.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define exp(x) pow(2.718281828, (x)) 6 | 7 | int main(){ 8 | double t, d, h, e; 9 | char input[30]; 10 | 11 | while(gets(input)){ 12 | if(0==strcmp(input, "E")) return 0; 13 | sscanf(input, "T %lf D %lf", &t, &d); 14 | e = 6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))); 15 | h = (0.5555)*(e-10.0); 16 | printf("%s H %.1lf\n", input, t+h); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/3299/13724839_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define exp(x) pow(2.718281828, (x)) 6 | 7 | int main(){ 8 | double t, d, h, e; 9 | char input[30]; 10 | 11 | while(gets(input)){ 12 | if(0==strcmp(input, "E")) return 0; 13 | sscanf(input, "T %lf D %lf", &t, &d); 14 | e = 6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))); 15 | h = (0.5555)*(e-10.0); 16 | printf("%s H %.1lf\n", input, t+h); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/3299/13724861_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define exp(x) pow(2.718281828, (x)) 6 | 7 | int main(){ 8 | double t, d, h, e; 9 | char input[30]; 10 | 11 | while(gets(input)){ 12 | if(0==strcmp(input, "E")) return 0; 13 | sscanf(input, "T %lf D %lf", &t, &d); 14 | e = 6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))); 15 | h = (0.5555)*(e-10.0); 16 | printf("T %.1lf D %.1lf H %.1lf\n", t, d, t+h); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /poj-cpp/1005/13715971_AC_0MS_148K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PI 3.1416 5 | 6 | int main(){ 7 | double x, y, r, s; 8 | int nCase, day, t=0; 9 | scanf("%d", &nCase); 10 | while(nCase--){ 11 | day = 0; 12 | scanf("%lf%lf", &x, &y); 13 | r = sqrt(x*x+y*y); 14 | s = PI*r*r/2; 15 | day = s/50; 16 | printf("Property %d: This property will begin eroding in year %d.\n", ++t, day+1); 17 | } 18 | printf("END OF OUTPUT.\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2533/14339630_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], g[2000], N, i, j, maxs=0; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | 4 | char S1[49] = {"`1234567890QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,."}; 5 | char S2[49] = {"1234567890-WERTYUIOP[]\\SDFGHJKL;'XCVBNM,./"}; 6 | int maps[128]; 7 | 8 | int main() 9 | { 10 | for(int i=0; i<42; i++) 11 | maps[S2[i]] = i; 12 | while(int ch=getchar()) { 13 | if(EOF==ch) break; 14 | if(ch==' ' || ch=='\n') putchar(ch); 15 | else putchar(S1[maps[ch]]); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/3100/14366722_AC_0MS_388K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int B, N; 7 | 8 | while(scanf("%d%d", &B, &N)) { 9 | if(B==0 && N==0) break; 10 | int l = floor(pow(B, 1.0/N)); 11 | int r = l+1; 12 | if(fabs(pow(l, N)-B) < fabs(pow(r, N)-B)) { 13 | printf("%d\n", l); 14 | } else { 15 | printf("%d\n", r); 16 | } 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/3299/13724849_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define exp(x) pow(2.718281828, (x)) 6 | 7 | int main(){ 8 | double t, d, h, e; 9 | char input[30]; 10 | 11 | while(gets(input)){ 12 | if(0==strcmp(input, "E")) return 0; 13 | sscanf(input, "T %lf D %lf", &t, &d); 14 | e = 6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))); 15 | h = (0.5555)*(e-10.0); 16 | printf("T %.1lf D %.1lf H %.1lf\n", t, d, t+h); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/3981/14723653_AC_0MS_336K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str[1024]; 7 | 8 | while(gets(str)) { 9 | int l = strlen(str); 10 | for(int i=0; i 2 | 3 | char str[20][25], N; 4 | 5 | int main() 6 | { 7 | int nCase, s, e, i; 8 | 9 | nCase = 0; 10 | while(scanf("%d", &N) && N) { 11 | for(i=0; i0; N-=2) printf("%s\n", str[N]); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2371/14714908_RE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[128]; 7 | 8 | int main() 9 | { 10 | int N, n; 11 | char str[1024]; 12 | 13 | scanf("%d", &N); 14 | for(int i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[5005]; 7 | 8 | int main() 9 | { 10 | int N, n; 11 | char str[1024]; 12 | 13 | scanf("%d", &N); 14 | for(int i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long arr[30000], N, i, sum, rzt; 9 | 10 | scanf("%lld", &N); 11 | sum = 0; 12 | for(i=0; i1; i--) rzt += (sum-=arr[i]); 19 | printf("%lld\n", rzt); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/2181/14816531_AC_63MS_1476K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 160000; 7 | int dp[maxn][2]; 8 | 9 | int main() 10 | { 11 | int N, n, ans = 0; 12 | 13 | scanf("%d", &N); 14 | for(int i=1; i<=N; i++) { 15 | scanf("%d", &n); 16 | dp[i][0] = max(dp[i-1][0], dp[i-1][1]+n); 17 | dp[i][1] = max(dp[i-1][1], dp[i-1][0]-n); 18 | } 19 | printf("%d\n", max(dp[N][0], dp[N][1])); 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /poj-cpp/2538/14872463_AC_16MS_316K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char S1[49] = {"`1234567890-QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,."}; 5 | char S2[49] = {"1234567890-=WERTYUIOP[]\\SDFGHJKL;'XCVBNM,./"}; 6 | int maps[128]; 7 | 8 | int main() 9 | { 10 | for(int i=0; i<43; i++) 11 | maps[S2[i]] = i; 12 | while(int ch=getchar()) { 13 | if(EOF==ch) break; 14 | if(ch==' ' || ch=='\n') putchar(ch); 15 | else putchar(S1[maps[ch]]); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/2583/14792642_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(int a, int b, int c, int x) 4 | { 5 | return a*x*x + b*x + c; 6 | } 7 | 8 | int main() 9 | { 10 | int x, y, z; 11 | 12 | while(~scanf("%d%d%d", &x, &y, &z)) { 13 | int a = (x-2*y+z) / 2; 14 | int b = y - a - x; 15 | int c = x; 16 | printf("%d ", f(a, b, c, 3)); 17 | printf("%d ", f(a, b, c, 4)); 18 | printf("%d\n", f(a, b, c, 5)); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/2602/14333990_TLE.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 15 | if(num[i]>=10) { 16 | num[i] -= 10; 17 | num[i-1] += 1; 18 | } 19 | } 20 | for(i=0; i 2 | 3 | char str[15][26], N; 4 | 5 | int main() 6 | { 7 | int nCase, s, e, i; 8 | 9 | nCase = 0; 10 | while(scanf("%d", &N) && N) { 11 | for(i=0; i0; N-=2) printf("%s\n", str[N]); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2371/14714914_AC_47MS_784K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[100005]; 7 | 8 | int main() 9 | { 10 | int N, n; 11 | char str[1024]; 12 | 13 | scanf("%d", &N); 14 | for(int i=0; i 2 | 3 | int num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 15 | if(num[i]>=10) { 16 | num[i] -= 10; 17 | num[i-1] += 1; 18 | } 19 | } 20 | for(i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | char str[1024]; 7 | int arr[1024], i, l, sum; 8 | 9 | while(gets(str) && str[0]!='#') { 10 | l = strlen(str); 11 | sum = 0; 12 | for(i=0; i 2 | 3 | int main(){ 4 | int x, y, m, n, l; 5 | int cnt; 6 | 7 | while(scanf("%d%d%d%d%d", &x, &y, &m, &n, &l)!=EOF){ 8 | cnt = 0; 9 | if(x!=y && m==n){ 10 | printf("Impossible\n"); 11 | continue; 12 | } 13 | while(x!=y){ 14 | x += m; 15 | if(x>=l) x%=l; 16 | y += n; 17 | if(y>=l) y%=l; 18 | cnt ++; 19 | } 20 | printf("%d\n", cnt); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /poj-cpp/1061/13870638_WA.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | int main(){ 6 | int x, y, a, b, L, i, t1, t2, faild; 7 | 8 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 9 | t1 = y-x; 10 | if(!t1){ 11 | printf("0\n"); 12 | continue; 13 | } 14 | t2 = 1; 15 | faild = 0; 16 | for(i=1; ; i++){ 17 | t2 = a*i%L - b*i%L; 18 | if(t2==t1) break; 19 | if(!t2){ 20 | faild = 1; 21 | break; 22 | } 23 | } 24 | if(faild) printf("Impossible\n"); 25 | else printf("%d\n", i); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/2352/13943261_TLE.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int N, i, j, x[20000], y[20000], rand[20000], cnt; 7 | 8 | scanf("%d", &N); 9 | for(i=0; i 2 | 3 | int bowl[21]; 4 | 5 | void flip(int n) 6 | { 7 | bowl[n-1] ^= 1; 8 | bowl[n] ^= 1; 9 | bowl[n+1] ^= 1; 10 | } 11 | 12 | int main() 13 | { 14 | for(int i=0; i<20; i++) 15 | scanf("%d", &bowl[i]); 16 | int cnt = 0; 17 | for(int i=0; i<20; i++) { 18 | if(bowl[i]==1) { 19 | flip(i+1); 20 | cnt++; 21 | } 22 | } 23 | printf("%d\n", cnt); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/3250/14785468_AC_172MS_672K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int que[85000], N, top, cnt; 4 | 5 | int main() 6 | { 7 | int a; 8 | unsigned long long ans = 0; 9 | top = cnt = 0; 10 | scanf("%d", &N); 11 | while(N--) { 12 | scanf("%d", &a); 13 | while(cnt && que[top-1]<=a) { 14 | top--; cnt--; 15 | } 16 | ans += cnt; 17 | que[top++] = a; cnt++; 18 | } 19 | printf("%lld\n", ans); 20 | 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /poj-cpp/3624/13967980_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int V, N, f[3500], v[3500], w[3500], i, j; 9 | 10 | scanf("%d%d", &N, &V); 11 | for(i=0; i=v[i]; j--){ 16 | f[j] = max(f[j], f[j-v[i]]+w[i]); 17 | } 18 | } 19 | printf("%d\n", f[V]); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /poj-cpp/1061/13870667_CE.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | int main(){ 6 | _int64 x, y, a, b, L, i, t1, t2, faild; 7 | 8 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 9 | t1 = y-x; 10 | if(!t1){ 11 | printf("0\n"); 12 | continue; 13 | } 14 | t2 = 1; 15 | faild = 0; 16 | for(i=1; ; i++){ 17 | t2 = a*i%L - b*i%L; 18 | if(t2==t1) break; 19 | if(!t2){ 20 | faild = 1; 21 | break; 22 | } 23 | } 24 | if(faild) printf("Impossible\n"); 25 | else printf("%I64d\n", i); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/1061/13870642_TLE.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | int main(){ 6 | long long x, y, a, b, L, i, t1, t2, faild; 7 | 8 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 9 | t1 = y-x; 10 | if(!t1){ 11 | printf("0\n"); 12 | continue; 13 | } 14 | t2 = 1; 15 | faild = 0; 16 | for(i=1; ; i++){ 17 | t2 = a*i%L - b*i%L; 18 | if(t2==t1) break; 19 | if(!t2){ 20 | faild = 1; 21 | break; 22 | } 23 | } 24 | if(faild) printf("Impossible\n"); 25 | else printf("%lld\n", i); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/1061/13870670_TLE.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | int main(){ 6 | long long x, y, a, b, L, i, t1, t2, faild; 7 | 8 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 9 | t1 = y-x; 10 | if(!t1){ 11 | printf("0\n"); 12 | continue; 13 | } 14 | t2 = 1; 15 | faild = 0; 16 | for(i=1; ; i++){ 17 | t2 = a*i%L - b*i%L; 18 | if(t2==t1) break; 19 | if(!t2){ 20 | faild = 1; 21 | break; 22 | } 23 | } 24 | if(faild) printf("Impossible\n"); 25 | else printf("%Ild\n", i); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/3299/13724866_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define exp(x) pow(2.718281828, (x)) 6 | 7 | int main(){ 8 | double t, d, h, e; 9 | char input[30]; 10 | 11 | while(gets(input)){ 12 | t = d = h = e =0; 13 | if(0==strcmp(input, "E")) return 0; 14 | sscanf(input, "T %lf D %lf", &t, &d); 15 | e = 6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))); 16 | h = (0.5555)*(e-10.0); 17 | printf("T %.1lf D %.1lf H %.1lf\n", t, d, t+h); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /poj-cpp/1050/13827328_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i, j, N, root[128][128]; 5 | 6 | while(~scanf("%d", &N)){ 7 | for(i=0; i=0; i--){ 14 | for(j=0; j<=i; j++){ 15 | root[i][j] += root[i+1][j]>root[i+1][j+1]?root[i+1][j]:root[i+1][j+1]; 16 | } 17 | } 18 | 19 | printf("%d\n", root[0][0]); 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /poj-cpp/1423/14216226_TLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int solve(int n); 5 | 6 | int main() 7 | { 8 | int T, n; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d", &n); 13 | printf("%d\n", solve(n)); 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | int solve(int n) 20 | { 21 | int i; 22 | 23 | double ans = 1; 24 | for(i=n; i>0; i--) { 25 | ans += log10((double)i); 26 | } 27 | return ans; 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/2602/14333994_TLE.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 15 | if(num[i]>=10) { 16 | num[i] -= 10; 17 | num[i-1] += 1; 18 | } 19 | } 20 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int V, N, f[35000], v[35000], w[35000], i, j; 9 | 10 | scanf("%d%d", &N, &V); 11 | for(i=0; i=v[i]; j--){ 16 | f[j] = max(f[j], f[j-v[i]]+w[i]); 17 | } 18 | } 19 | printf("%d\n", f[V]); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /poj-cpp/3628/14829344_AC_172MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, B, cow[20]; 6 | scanf("%d%d", &N, &B); 7 | for(int i=0; i=B && sum-B 2 | 3 | int solve(int n, int k); 4 | 5 | int main(){ 6 | int k, i, t; 7 | 8 | while(scanf("%d", &k), k){ 9 | for(i=1; ; i++){ 10 | if(solve(k, i)) break; 11 | } 12 | printf("%d\n", i); 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | int solve(int n, int k){ 19 | int i, t, sum; 20 | sum = n*2; 21 | for(i=0, t=-1; i 4 | 5 | int main(){ 6 | long long x, y, a, b, L, i, t1, t2, faild; 7 | 8 | while(~scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &L)){ 9 | t1 = y-x; 10 | if(!t1){ 11 | printf("0\n"); 12 | continue; 13 | } 14 | t2 = 1; 15 | faild = 0; 16 | for(i=1; ; i++){ 17 | t2 = a*i%L - b*i%L; 18 | if(t2==t1) break; 19 | if(!t2){ 20 | faild = 1; 21 | break; 22 | } 23 | } 24 | if(faild) printf("Impossible\n"); 25 | else printf("%Ild\n", i); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /poj-cpp/1159/13975884_MLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int d[7000][7000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975886_MLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int d[5000][5000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975891_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int d[3000][3000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975892_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int d[4000][4000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975933_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | short d[1000][1000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975935_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | short d[5000][5000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975939_MLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | short d[6000][6000]; 8 | 9 | int main() 10 | { 11 | int N, i, j; 12 | char str[8000]; 13 | 14 | scanf("%d", &N); 15 | scanf("%s", str+1); 16 | memset(d, 0, sizeof(d)); 17 | for (i=N; i>0; i--) { 18 | for (j=i; j<=N; j++) { 19 | if (str[i] == str[j]) { 20 | d[i][j] = d[i+1][j-1]; 21 | } else { 22 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 23 | } 24 | } 25 | } 26 | printf("%d\n", d[1][N]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/1837/14402377_AC_141MS_1668K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int dp[21][16001], N, M; 5 | int pos[21], wei[21]; 6 | 7 | int main() 8 | { 9 | memset(dp, 0, sizeof(dp)); 10 | scanf("%d%d", &N, &M); 11 | for(int i=1; i<=N; i++) 12 | scanf("%d", &pos[i]); 13 | for(int i=1; i<=M; i++) 14 | scanf("%d", &wei[i]); 15 | dp[0][7500] = 1; 16 | for(int i=1; i<=M; i++) { 17 | for(int j=0; j<15001; j++) { 18 | for(int k=1; k<=N; k++) { 19 | dp[i][j+wei[i]*pos[k]] += dp[i-1][j]; 20 | } 21 | } 22 | } 23 | printf("%d\n", dp[M][7500]); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /poj-cpp/3325/14699344_AC_0MS_396K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int N, n, sum, maxs, mins; 7 | 8 | while(scanf("%d", &N) && N) { 9 | sum = 0; mins = 1024; maxs = -1; 10 | for(int i=0; imaxs) maxs = n; 14 | if(n 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int maps[110][110], dp[110][110], F, V; 8 | 9 | int main() 10 | { 11 | int i, j; 12 | 13 | scanf("%d%d", &F, &V); 14 | for(i=1; i<=F; i++) { 15 | for(j=1; j<=V; j++) { 16 | scanf("%d", &maps[i][j]); 17 | } 18 | } 19 | memset(dp, 0, sizeof(dp)); 20 | for(i=1; i<=F; i++) { 21 | for(j=1; j<=V; j++) { 22 | dp[i][j] = max(dp[i][j-1], dp[i-1][j-1]+maps[i][j]); 23 | } 24 | } 25 | printf("%d\n", dp[F][V]); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /poj-cpp/1163/13824911_AC_32MS_212K.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i, j, N, root[128][128]; 5 | 6 | while(~scanf("%d", &N)){ 7 | for(i=0; i=0; i--){ 14 | for(j=0; j<=i; j++){ 15 | root[i][j] += root[i+1][j]>root[i+1][j+1]?root[i+1][j]:root[i+1][j+1]; 16 | } 17 | } 18 | 19 | printf("%d\n", root[0][0]); 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /poj-cpp/2249/14708576_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long long cal(int n, int m) 5 | { 6 | if(n-m < m) m = n-m; 7 | long long a = 1; 8 | for(int i=0; i 2 | 3 | const int maxn = 1e6+1; 4 | int fact[maxn], dp[maxn]; 5 | 6 | void sieve() 7 | { 8 | for(int i=2; i*i 2 | 3 | int main() 4 | { 5 | int N, i, maxs, flag, a, b; 6 | 7 | while(scanf("%d", &N) && N) { 8 | flag = 0; maxs = 8; 9 | for(i=1; i<=N; i++) { 10 | scanf("%d%d", &a, &b); 11 | if(a+b>maxs) { 12 | maxs = a+b; 13 | flag = i; 14 | } 15 | } 16 | printf("%d\n", flag); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/3086/14699361_AC_0MS_396K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int sum[305]; 5 | int wei[305]; 6 | 7 | int main() 8 | { 9 | int T, n; 10 | 11 | sum[0] = 0; 12 | for(int i=1; i<=301; i++) 13 | sum[i] = i + sum[i-1]; 14 | for(int i=1; i<=300; i++) 15 | wei[i] = wei[i-1] + i*sum[i+1]; 16 | 17 | scanf("%d", &T); 18 | for(int nCase=1; nCase<=T; nCase++) { 19 | scanf("%d", &n); 20 | printf("%d %d %d\n", nCase, n, wei[n]); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/3627/14814057_RE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int cow[10005]; 7 | 8 | int cmp(int a, int b) 9 | { 10 | return a > b; 11 | } 12 | 13 | int main() 14 | { 15 | int N, B; 16 | 17 | scanf("%d%d", &N, &B); 18 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | char ch; 6 | 7 | while((ch=getchar()) != '#') { 8 | if(ch==' ') printf("%%20"); 9 | else if(ch=='!') printf("%%21"); 10 | else if(ch=='$') printf("%%24"); 11 | else if(ch=='%') printf("%%25"); 12 | else if(ch=='(') printf("%%28"); 13 | else if(ch==')') printf("%%29"); 14 | else if(ch=='*') printf("%%2a"); 15 | else putchar(ch); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/3663/14734761_AC_47MS_436K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int len[20005]; 8 | int N, S; 9 | 10 | int main() 11 | { 12 | scanf("%d%d", &N, &S); 13 | for(int i=0; i 2 | #include 3 | 4 | int min(int a, int b) 5 | { 6 | return a0; i--) { 20 | for (j=i; j<=N; j++) { 21 | if (str[i] == str[j]) { 22 | d[i][j] = d[i+1][j-1]; 23 | } else { 24 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 25 | } 26 | } 27 | } 28 | printf("%d\n", d[1][N]); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /poj-cpp/1159/13975985_RE.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int min(int a, int b) 5 | { 6 | return a0; i--) { 20 | for (j=i; j<=N; j++) { 21 | if (str[i] == str[j]) { 22 | d[i][j] = d[i+1][j-1]; 23 | } else { 24 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 25 | } 26 | } 27 | } 28 | printf("%d\n", d[1][N]); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /poj-cpp/2000/13954845_AC_16MS_160K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, i, sum, t, nn; 6 | 7 | while(scanf("%d", &n), n){ 8 | sum = 0; 9 | for(i=0, nn=0, t=1; i 2 | 3 | int maps[26] = {0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2}; 4 | 5 | int main() 6 | { 7 | char str[30]; 8 | 9 | while(~scanf("%s", str)) { 10 | for(int i=0; str[i]; i++) { 11 | if(!maps[str[i]-'A']) continue; 12 | if(maps[str[i]-'A']==maps[str[i-1]-'A']) continue; 13 | printf("%d", maps[str[i]-'A']); 14 | } 15 | printf("\n"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/3751/14865453_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int ye, mo, da, ho, mi, se, T, ok; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d/%d/%d-%d:%d:%d", &ye, &mo, &da, &ho, &mi, &se); 10 | if(ho>=12) ok = 1; 11 | else ok = 0; 12 | if(ho>12) ho -= 12; 13 | else if(ho==0) ho = 12; 14 | printf("%02d/%02d/%02d-%02d:%02d:%02d", mo, da, ye, ho, mi, se); 15 | printf("%s\n", ok ? "pm": "am"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /poj-cpp/2104/13944114_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int cmp(int a, int b) 7 | { 8 | return a-b; 9 | } 10 | 11 | int main() 12 | { 13 | int arr[200000], tmp[200000], N, i, Q, l, r, k; 14 | scanf("%d%d", &N, &Q); 15 | for(i=1; i<=N; i++){ 16 | scanf("%d", &arr[i]); 17 | } 18 | while(Q--){ 19 | scanf("%d%d%d", &l, &r, &k); 20 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 21 | sort(tmp+l, tmp+r+1, cmp); 22 | printf("%d\n", tmp[l+k-1]); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/2209/14912697_AC_32MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int pow(int x, int n) 4 | { 5 | int s = 1; 6 | while(n) { 7 | if(n&1) s *= x; 8 | x *= x; 9 | n >>= 1; 10 | } 11 | return s; 12 | } 13 | 14 | int main() 15 | { 16 | int n, ans, e, x; 17 | ans = 0; 18 | scanf("%d%d", &n, &e); 19 | while(n--) { 20 | scanf("%d", &x); 21 | x = pow(x, e); 22 | if(x > 0) ans += x; 23 | } 24 | printf("%d\n", ans); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2478/14798123_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int maxn = 1e6+1; 4 | long long fact[maxn], dp[maxn]; 5 | 6 | void sieve() 7 | { 8 | for(int i=2; i*i 2 | 3 | int val[200005], next[200005]; 4 | 5 | int main() 6 | { 7 | int N, i, j, n, v, cnt; 8 | 9 | while(~scanf("%d", &N)) { 10 | cnt = 1; 11 | next[0] = -1; 12 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int cow[20005]; 7 | 8 | int cmp(int a, int b) 9 | { 10 | return a > b; 11 | } 12 | 13 | int main() 14 | { 15 | int N, B; 16 | 17 | scanf("%d%d", &N, &B); 18 | for(int i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], g[2000], d[2000], N, i, j, maxs=0; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | 4 | int min(int a, int b) 5 | { 6 | return a0; i--) { 20 | for (j=i; j<=N; j++) { 21 | if (str[i] == str[j]) { 22 | d[i][j] = d[i+1][j-1]; 23 | } else { 24 | d[i][j] = min(d[i+1][j], d[i][j-1])+1; 25 | } 26 | } 27 | } 28 | printf("%d\n", d[1][N]); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /poj-cpp/2104/13944073_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int cmp(const void* a, const void* b) 5 | { 6 | return *(int*)a-*(int*)b; 7 | } 8 | 9 | int main() 10 | { 11 | int arr[200000], tmp[200000], N, i, Q, l, r, k; 12 | scanf("%d%d", &N, &Q); 13 | for(i=1; i<=N; i++){ 14 | scanf("%d", &arr[i]); 15 | } 16 | while(Q--){ 17 | scanf("%d%d%d", &l, &r, &k); 18 | for(i=l; i<=r; i++) tmp[i] = arr[i]; 19 | qsort(tmp+l, r-l+1, sizeof(int), cmp); 20 | printf("%d\n", tmp[l+k-1]); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/2513/14089319_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | map mp; 10 | char str[50]; 11 | 12 | while(~scanf("%s", str)) { 13 | mp[str]++; 14 | } 15 | map::iterator it; 16 | int cnt = 0; 17 | for(it=mp.begin(); it!=mp.end(); it++) { 18 | if(it->second%2!=0) cnt++; 19 | } 20 | if(cnt>2) printf("Impossible\n"); 21 | else printf("Possible\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/2478/14798158_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int maxn = 1e6+1; 4 | int fact[maxn]; 5 | long long dp[maxn]; 6 | 7 | void sieve() 8 | { 9 | for(int i=2; i*2 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], g[2000], d[2000], N, i, j, maxs=0; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 250005; 7 | long long arr[maxn], N; 8 | 9 | int main() 10 | { 11 | scanf("%d", &N); 12 | for(int i=0; i 2 | 3 | char str[15]; 4 | 5 | int main() 6 | { 7 | while(scanf("%s", str) && str[0]-'0') { 8 | printf("%s: ", str); 9 | for(int i=0; str[i]; i++) { 10 | if(str[i]>'4') 11 | str[i]--; 12 | } 13 | int s = 0; 14 | for(int i=0; str[i]; i++) { 15 | s *= 9; 16 | s += str[i]-'0'; 17 | } 18 | printf("%d\n", s); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/1157/14296021_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int maps[110][110], dp[110][110], F, V; 8 | 9 | int main() 10 | { 11 | int i, j; 12 | 13 | scanf("%d%d", &F, &V); 14 | for(i=1; i<=F; i++) { 15 | for(j=1; j<=V; j++) { 16 | scanf("%d", &maps[i][j]); 17 | } 18 | } 19 | for(i=0; i<=F; i++) for(j=0; j<=V; j++) dp[i][j] = -99999; 20 | for(i=1; i<=F; i++) { 21 | for(j=1; j<=V; j++) { 22 | dp[i][j] = max(dp[i][j-1], dp[i-1][j-1]+maps[i][j]); 23 | } 24 | } 25 | printf("%d\n", dp[F][V]); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /poj-cpp/1852/14871055_AC_141MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int l, n, T, c; 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d%d", &l, &n); 10 | double m = l/2.0, a = 1000001, b = 0; 11 | for(int i=0; i b) b = fabs(m-c); 15 | } 16 | printf("%d %d\n", (int)(m-a), (int)(m+b)); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /poj-cpp/2533/13937753_AC_32MS_144K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int N, arr[2000], tmp[2000], i, j, t, maxs=0; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[400][400], N; 7 | 8 | int main() 9 | { 10 | int i, j; 11 | 12 | scanf("%d", &N); 13 | for(i=1; i<=N; i++) { 14 | for(j=1; j<=i; j++) scanf("%d", &arr[i][j]); 15 | } 16 | for(i=N-1; i>0; i--) { 17 | for(j=1; j<=i; j++) { 18 | arr[i][j] += max(arr[i+1][j], arr[i+1][j+1]); 19 | } 20 | } 21 | printf("%d\n", arr[1][1]); 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/3176/14057552_AC_32MS_696K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[400][400], N; 7 | 8 | int main() 9 | { 10 | int i, j; 11 | 12 | scanf("%d", &N); 13 | for(i=1; i<=N; i++) { 14 | for(j=1; j<=i; j++) scanf("%d", &arr[i][j]); 15 | } 16 | for(i=N-1; i>0; i--) { 17 | for(j=1; j<=i; j++) { 18 | arr[i][j] += max(arr[i+1][j], arr[i+1][j+1]); 19 | } 20 | } 21 | printf("%d", arr[1][1]); 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/2291/14900274_AC_0MS_364K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int rop[1024], N, T; 8 | 9 | int main() 10 | { 11 | scanf("%d", &T); 12 | while(T--) { 13 | scanf("%d", &N); 14 | for(int i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[30]; 7 | 8 | int main() 9 | { 10 | int T, N; 11 | 12 | scanf("%d", &T); 13 | while(T--) { 14 | scanf("%d", &N); 15 | for(int i=0; i> 1; 19 | int sum = 0; 20 | sum += arr[m]-arr[0] + arr[N-1]-arr[m]; 21 | printf("%d\n", sum*2); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/1012/13890532_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int solve(int n, int k); 4 | 5 | int main(){ 6 | int k, i, t; 7 | 8 | while(scanf("%d", &k), k){ 9 | t=k*2; 10 | for(i=1; ; i++){ 11 | if(i%t 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, b, faild; 7 | 8 | while(~scanf("%d", &n)) { 9 | faild = 0; 10 | scanf("%d", &a); 11 | for(int k=1; k0 && c 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 250005; 7 | long long arr[maxn], N; 8 | 9 | int main() 10 | { 11 | scanf("%d", &N); 12 | for(int i=0; i 2 | 3 | int main() 4 | { 5 | int arr[30], i, j, k, cnt; 6 | 7 | while(1){ 8 | for(i=0; scanf("%d", &arr[i]) && arr[i] && arr[i]!=-1; i++) ; 9 | if(arr[i]==-1) break; 10 | cnt = 0; 11 | for(j=0; j 2 | 3 | char num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 18 | if(num[i]>'9') { 19 | num[i] -= 10; 20 | num[i-1] += 1; 21 | } 22 | } 23 | printf("%s\n", num); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/3637/14891874_AC_94MS_428K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int buy[20010], N; 7 | 8 | int main() 9 | { 10 | int T; 11 | scanf("%d", &T); 12 | while(T--) { 13 | scanf("%d", &N); 14 | for(int i=0; i=0; i-=3) { 19 | ans += buy[i]; 20 | } 21 | printf("%d\n", ans); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/2575/14766024_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, b, faild; 7 | 8 | while(~scanf("%d", &n)) { 9 | faild = 0; 10 | if(n>0) scanf("%d", &a); 11 | for(int k=1; k0 && c 2 | 3 | int num1[1000010], num2[1000010], N; 4 | 5 | int main() 6 | { 7 | int i; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i=0; i--) { 14 | num1[i] += num2[i]; 15 | } 16 | for(i=N-1; i>0; i--) { 17 | if(num1[i]>=10) { 18 | num1[i] -= 10; 19 | num1[i-1] += 1; 20 | } 21 | } 22 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char S1[1024], S2[1024]; 8 | int dp[1024][1024]; 9 | 10 | int main() 11 | { 12 | int N, M; 13 | 14 | scanf("%d%s%d%s", &M, S1+1, &N, S2+1); 15 | dp[0][0] = 0; 16 | for(int i=1; i<=M; i++) { 17 | for(int j=1; j<=N; j++) { 18 | if(S1[i]==S2[j]) dp[i][j] = dp[i-1][j-1]+1; 19 | else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 20 | } 21 | } 22 | printf("%d\n", N-dp[M][N]); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/3507/14821002_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int arr[6]; 6 | 7 | while(1) { 8 | int maxs = 0; 9 | int mins = 0x3f3f3f3f; 10 | int sum = 0; 11 | for(int i=0; i<6; i++) { 12 | scanf("%d", &arr[i]); 13 | if(arr[i]>maxs) maxs = arr[i]; 14 | if(arr[i] 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | int x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%d\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/2229/14152345_RE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int cnt; 4 | 5 | int dfs(int s, int N); 6 | 7 | int main() 8 | { 9 | int N, i; 10 | 11 | scanf("%d", &N); 12 | cnt = 0; 13 | dfs(0, N); 14 | printf("%d\n", cnt); 15 | 16 | return 0; 17 | } 18 | 19 | int dfs(int s, int N) 20 | { 21 | int i, t; 22 | 23 | if(N==0) cnt++; 24 | else 25 | for(i=s; i=0) dfs(i, N-t); 28 | else break; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /poj-cpp/1061/13873433_WA.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | long long x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%d\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/1326/14771131_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char t1[30], t2[30], type[10]; 6 | int m, ans = 0; 7 | 8 | while(scanf("%s", t1)) { 9 | if(t1[0]=='0') { 10 | printf("%d\n", ans); 11 | ans = 0; 12 | continue; 13 | } else if(t1[0]=='#') break; 14 | scanf("%s%d%s", t2, &m, type); 15 | if(type[0]=='F') ans += m*2; 16 | else if(type[0]=='B') ans += (int)(m*1.5+0.5); 17 | else ans += m<500 ? 500 : m; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /poj-cpp/1969/14723833_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | while(~scanf("%d", &n)) { 8 | int l = 0; int r = 10000; 9 | while(l> 1; 11 | if(m*(m+1)/2 < n) l = m+1; 12 | else r = m; 13 | } 14 | int s; 15 | int res = n - (l-1)*l/2; 16 | if(l & 1) s = res; 17 | else s = l-res+1; 18 | printf("TERM %d IS %d/%d\n", n, l-s+1, s); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/3224/14764588_AC_16MS_388K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int cnt[101]; 4 | 5 | int main() 6 | { 7 | int n, a; 8 | scanf("%d", &n); 9 | for(int i=0; imaxs) { 18 | maxs = cnt[i]; 19 | ans = i; 20 | } 21 | } 22 | printf("%d\n", ans+1); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /poj-cpp/3673/14090192_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m, n, arr1[20], arr2[20], i, j, cnt, na, ma; 6 | 7 | scanf("%d%d", &m, &n); 8 | ma = na = 0; 9 | while(m%10) { 10 | arr1[ma++] = m%10; 11 | m /= 10; 12 | } 13 | while(n%10) { 14 | arr2[na++] = n%10; 15 | n /= 10; 16 | } 17 | cnt = 0; 18 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int m, n, arr1[20], arr2[20], i, j, cnt, na, ma; 6 | 7 | scanf("%d%d", &m, &n); 8 | ma = na = 0; 9 | while(m%10) { 10 | arr1[ma++] = m%10; 11 | m /= 10; 12 | } 13 | while(n%10) { 14 | arr2[na++] = n%10; 15 | n /= 10; 16 | } 17 | cnt = 0; 18 | for(i=0; i 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | long long x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%lld\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/1157/14296239_AC_0MS_468K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int maps[110][110], dp[110][110], F, V; 8 | 9 | int main() 10 | { 11 | int i, j; 12 | 13 | scanf("%d%d", &F, &V); 14 | for(i=1; i<=F; i++) { 15 | for(j=1; j<=V; j++) { 16 | scanf("%d", &maps[i][j]); 17 | } 18 | } 19 | memset(dp, 0, sizeof(dp)); 20 | for(i=1; i<=F; i++) dp[i][i] = dp[i-1][i-1]+maps[i][i]; 21 | for(i=1; i<=F; i++) { 22 | for(j=i+1; j<=V; j++) { 23 | dp[i][j] = max(dp[i][j-1], dp[i-1][j-1]+maps[i][j]); 24 | } 25 | } 26 | printf("%d\n", dp[F][V]); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /poj-cpp/2533/13927940_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], cnt[2000], N, i, j, maxs; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int m, n, arr1[20], arr2[20], i, j, cnt, na, ma; 6 | 7 | scanf("%d%d", &m, &n); 8 | ma = na = 0; 9 | while(m) { 10 | arr1[ma++] = m%10; 11 | m /= 10; 12 | } 13 | while(n) { 14 | arr2[na++] = n%10; 15 | n /= 10; 16 | } 17 | cnt = 0; 18 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | double hei[1024], g[1024]; 8 | 9 | int main() 10 | { 11 | int N; 12 | scanf("%d", &N); 13 | for(int i=0; ians) ans = r; 22 | } 23 | printf("%d\n", N-ans-1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/1836/14907022_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | double hei[1024], g[1024]; 8 | 9 | int main() 10 | { 11 | int N; 12 | scanf("%d", &N); 13 | for(int i=0; ians) ans = r; 22 | } 23 | printf("%d\n", N-ans-1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/1936/13972730_AC_16MS_448K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | char str1[150000], str2[150000]; 8 | int l1, l2, i, j, cnt; 9 | 10 | while (~scanf("%s%s", str1, str2)){ 11 | l2 = strlen(str2); 12 | for (i = j = 0; i < l2 && str1[j] != '\0'; i++){ 13 | if (str1[j] == str2[i]) { 14 | j++; 15 | } 16 | } 17 | 18 | 19 | if (str1[j]=='\0') printf("Yes\n"); 20 | else printf("No\n"); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /poj-cpp/2407/14712803_AC_0MS_396K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int euler_phi(int n) 5 | { 6 | int m = (int)(sqrt(n)+0.5); 7 | int ans = n; 8 | for(int i=2; i<=m; i++) { 9 | if(n%i==0) { 10 | ans = ans/i * (i-1); 11 | while(n%i==0) n /= i; 12 | } 13 | } 14 | if(n>1) ans = ans/n * (n-1); 15 | return ans; 16 | } 17 | 18 | int main() 19 | { 20 | int n; 21 | 22 | while(scanf("%d", &n) && n) { 23 | printf("%d\n", euler_phi(n)); 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /poj-cpp/3624/14718840_AC_266MS_440K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | const int maxn = 13000; 8 | 9 | int V, N, f[maxn], v[maxn], w[maxn]; 10 | 11 | int main() 12 | { 13 | int i, j; 14 | 15 | memset(f, 0, sizeof(f)); 16 | scanf("%d%d", &N, &V); 17 | for(i=0; i=v[i]; j--){ 22 | f[j] = max(f[j], f[j-v[i]]+w[i]); 23 | } 24 | } 25 | printf("%d\n", f[V]); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /poj-cpp/3749/14678715_AC_0MS_332K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char maps[30] = "VWXYZABCDEFGHIJKLMNOPQRSTU"; 5 | 6 | int main() 7 | { 8 | char str[10], ch; 9 | 10 | while(scanf("%s", str)) { 11 | if(!strcmp(str, "ENDOFINPUT")) 12 | break; 13 | getchar(); 14 | while((ch=getchar())!='\n') 15 | if(ch<='Z' && ch>='A') 16 | putchar(maps[ch-'A']); 17 | else putchar(ch); 18 | putchar('\n'); 19 | scanf("%s", str); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /poj-cpp/1061/13873441_WA.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | long long x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%lld\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/1061/13873449_WA.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | long long x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%lld\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/1061/13873545_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int gcd(int a, int b){ 5 | if(!b) return a; 6 | else return gcd(b, a%b); 7 | } 8 | 9 | long long lcm(int a, int b){ 10 | return a*b/gcd(a, b); 11 | } 12 | 13 | 14 | int main(){ 15 | int x, y, a, b, L; 16 | long long n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%lld\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/2909/14555048_AC_0MS_760K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int prim[100005]; 6 | 7 | void get_prim() 8 | { 9 | memset(prim, 0, sizeof(prim)); 10 | prim[0] = prim[1] = 1; 11 | int n = sqrt(100000+0.5); 12 | for(int i=2; i<=n; i++) { 13 | if(prim[i]) continue; 14 | for(int j = i*i; j<100000; j+=i) { 15 | prim[j] = 1; 16 | } 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | get_prim(); 23 | int n; 24 | 25 | while(scanf("%d", &n) && n) { 26 | int ans = 0; 27 | for(int i=2; i<=n/2; i++) { 28 | if(prim[i]) continue; 29 | if(!prim[n-i]) ans++; 30 | } 31 | printf("%d\n", ans); 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /poj-cpp/3100/14366669_CE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int B, N; 7 | 8 | while(scanf("%d%d", &B, &N)) { 9 | if(B==0 && N==0) break; 10 | int m = (int)(pow(B, 1.0/N)+0.5); 11 | int l = m-1, r = m+1; 12 | if(fabs(pow(l, N)-B) < fabs(pow(m, N)-B)) { 13 | printf("%d\n", l); 14 | } else if(fabs(pow(m, N))-B < fabs(pow(r, N)-B)) { 15 | printf("%d\n", m); 16 | } else { 17 | printf("%d\n", r); 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/2602/14334009_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 18 | if(num[i]>'9') { 19 | num[i] -= 10; 20 | num[i-1] += 1; 21 | } 22 | } 23 | if(num[0]>'9') num[0] -= 10; 24 | printf("%s\n", num); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2602/14334012_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char num[10000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 18 | if(num[i]>'9') { 19 | num[i] -= 10; 20 | num[i-1] += 1; 21 | } 22 | } 23 | if(num[0]>'9') num[0] -= 10; 24 | printf("%s\n", num); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/1061/13873550_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int gcd(int a, int b){ 5 | if(!b) return a; 6 | else return gcd(b, a%b); 7 | } 8 | 9 | long long lcm(int a, int b){ 10 | return (long long)a*b/gcd(a, b); 11 | } 12 | 13 | 14 | int main(){ 15 | int x, y, a, b, L; 16 | long long n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | 22 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 23 | for(i=1; i<=n; i++){ 24 | if( (x+a*i)%L == (y+b*i)%L ) break; 25 | } 26 | if(i==n+1) printf("Impossible\n"); 27 | else printf("%lld\n", i); 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /poj-cpp/3100/14366674_AC_0MS_384K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int B, N; 7 | 8 | while(scanf("%d%d", &B, &N)) { 9 | if(B==0 && N==0) break; 10 | int m = (int)(pow(B, 1.0/N)+0.5); 11 | int l = m-1, r = m+1; 12 | if(fabs(pow(l, N)-B) < fabs(pow(m, N)-B)) { 13 | printf("%d\n", l); 14 | } else if(fabs(pow(m, N))-B < fabs(pow(r, N)-B)) { 15 | printf("%d\n", m); 16 | } else { 17 | printf("%d\n", r); 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/3356/14827226_AC_0MS_4376K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | char S1[1024], S2[1024]; 8 | int dp[1024][1024]; 9 | 10 | int main() 11 | { 12 | int N, M; 13 | 14 | while(~scanf("%d%s%d%s", &M, S1+1, &N, S2+1)) { 15 | dp[0][0] = 0; 16 | for(int i=1; i<=M; i++) { 17 | for(int j=1; j<=N; j++) { 18 | if(S1[i]==S2[j]) dp[i][j] = dp[i-1][j-1]+1; 19 | else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 20 | } 21 | } 22 | printf("%d\n", N-dp[M][N]); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/1423/14216277_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | float arr[10000001]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(10000000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/1423/14216283_RE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | double arr[1000001]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(1000000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/1423/14216288_MLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | double arr[8388000]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(8388000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/1423/14216290_MLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | double arr[8380000]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(8379999); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/1423/14216294_RE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | double arr[8000000]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(7999999); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/2229/14153166_RE.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int arr[1100000]; 6 | 7 | int get_n(int n); 8 | int get(int n, int m); 9 | 10 | int main() 11 | { 12 | int N; 13 | 14 | scanf("%d", &N); 15 | memset(arr, 0, sizeof(arr)); 16 | arr[1] = 1; 17 | printf("%d\n", get_n(N)); 18 | 19 | return 0; 20 | } 21 | 22 | int get_n(int n) 23 | { 24 | int ans = 0; 25 | 26 | if(arr[n]) return arr[n]; 27 | else { 28 | ans += get_n(n-1); 29 | if(n%2==0) ans += get_n(n/2); 30 | } 31 | 32 | return arr[n] = ans%1000000000; 33 | } 34 | -------------------------------------------------------------------------------- /poj-cpp/2231/14699435_TLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | const int maxn = 10005; 9 | 10 | int N, arr[maxn]; 11 | 12 | int main() 13 | { 14 | ll ans = 0; 15 | scanf("%d", &N); 16 | for(int i=0; i 2 | #include 3 | #include 4 | 5 | double arr[10000001]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(10000000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", (int)arr[n]); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | 28 | arr[0] = 1; 29 | for(i=1; i<=n; i++) { 30 | arr[i] = log10(i)+arr[i-1]; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /poj-cpp/1656/14559639_AC_0MS_412K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int maps[105][105]; 5 | 6 | int main() 7 | { 8 | int T, a, b, c; 9 | char cmd[10]; 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%s%d%d%d", cmd, &a, &b, &c); 13 | if(cmd[0]=='W') { 14 | for(int i=a; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int arr[510000]; 7 | 8 | int main() 9 | { 10 | int m, i; 11 | set st; 12 | 13 | arr[0] = 0; 14 | st.insert(0); 15 | for(i=1; i<=500000; i++) { 16 | int n = arr[i-1]-i; 17 | if(n>0 && st.find(n)==st.end()) arr[i] = n; 18 | else arr[i] = arr[i-1]+i; 19 | st.insert(arr[i]); 20 | } 21 | while(scanf("%d", &m)) { 22 | if(m==-1) break; 23 | printf("%d\n", arr[m]); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2299/13759727_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int nums, a[500000]; 5 | int i, j, n, t; 6 | 7 | while(scanf("%d", &nums)!=EOF){ 8 | if(nums==0) return 0; 9 | n = 0; 10 | for(i=0; i0; i--){ 14 | for(j=0; ja[j+1]){ 16 | t = a[j+1]; 17 | a[j+1] = a[j]; 18 | a[j] = t; 19 | n++; 20 | } 21 | } 22 | } 23 | printf("%d\n", n); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/2533/13927884_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], cnt[2000], N, i, j, maxs; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], cnt[2000], N, i, j, maxs; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[2000], cnt[2000], N, i, j, maxs; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i 2 | #include 3 | 4 | const int INF = 0x3f3f3f3f; 5 | 6 | int main() 7 | { 8 | int a, b, c; 9 | 10 | while(~scanf("%d", &a)) { 11 | int ans = INF; 12 | for(b=1; ; b++) { 13 | if(a!=b && 0==(a*b+1)%(b-a)) { 14 | c = (a*b+1)/(b-a); 15 | if(c<0) continue; 16 | if(b+cc) break; 18 | } 19 | } 20 | printf("%d\n", ans); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/1775/14918263_TLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int fact[100], n; 6 | fact[0] = 1; 7 | for(int i=1; i<15; i++) 8 | fact[i] = i*fact[i-1]; 9 | while(scanf("%d", &n) && n>=0) { 10 | int ok = 0; 11 | for(int s=0; s<1<<15; s++) { 12 | int ss = 0; 13 | for(int i=0; i<15; i++) 14 | if(1< 2 | #include 3 | 4 | int main() 5 | { 6 | for(int i=2992; i<10000; i++) { 7 | int n = i; 8 | int s = 0; 9 | while(n) { 10 | s += n%16; 11 | n /= 16; 12 | } 13 | n = i; 14 | int s2 = 0; 15 | while(n) { 16 | s2 += n%12; 17 | n /= 12; 18 | } 19 | int s1 = i%10 + (i/10)%10 + (i/100)%10 + i/1000; 20 | if(s==s1 && s1==s2) printf("%d\n", i); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/2231/14699438_AC_985MS_432K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | const int maxn = 10005; 9 | 10 | int N, arr[maxn]; 11 | 12 | int main() 13 | { 14 | ll ans = 0; 15 | scanf("%d", &N); 16 | for(int i=0; i 2 | 3 | char num[1000010]; 4 | int N; 5 | 6 | int main() 7 | { 8 | int i, a, b; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i0; i--) { 19 | if(num[i]>'9') { 20 | num[i] -= 10; 21 | num[i-1] += 1; 22 | } 23 | } 24 | if(num[0]>'9') num[0] -= 10; 25 | printf("%s\n", num); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /poj-cpp/2602/14334021_AC_469MS_1360K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char num[1000010]; 4 | int N; 5 | 6 | int main() 7 | { 8 | int i, a, b; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i0; i--) { 19 | if(num[i]>'9') { 20 | num[i] -= 10; 21 | num[i-1] += 1; 22 | } 23 | } 24 | if(num[0]>'9') num[0] -= 10; 25 | printf("%s\n", num); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /poj-cpp/3673/14090207_AC_0MS_132K.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m, n; 6 | char arr1[10], arr2[10], i, j, na, ma; 7 | short cnt; 8 | 9 | scanf("%d%d", &m, &n); 10 | ma = na = 0; 11 | while(m) { 12 | arr1[ma++] = m%10; 13 | m /= 10; 14 | } 15 | while(n) { 16 | arr2[na++] = n%10; 17 | n /= 10; 18 | } 19 | cnt = 0; 20 | for(i=0; i 2 | 3 | int main() 4 | { 5 | int arr[10], T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | for(int i=0; i<4; i++) scanf("%d", &arr[i]); 10 | int a = arr[3]-arr[2]; 11 | int b = arr[2]-arr[1]; 12 | int c = arr[1]-arr[0]; 13 | for(int i=0; i<4; i++) printf("%d ", arr[i]); 14 | if(a==b && b==c) { 15 | printf("%d\n", arr[3]+a); 16 | } else { 17 | printf("%d\n", arr[3]*(arr[2]/arr[1])); 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /poj-cpp/3903/13929317_AC_63MS_1932K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[150000], t[150000], cnt[150000], N, i, j, maxs; 9 | 10 | while(~scanf("%d", &N)){ 11 | for(i=0; i 2 | 3 | int gcd(int a, int b) 4 | { 5 | return b ? gcd(b, a%b) : a; 6 | } 7 | 8 | int main() 9 | { 10 | int a, b, c, d; 11 | char op; 12 | while(~scanf("%d/%d%c%d/%d", &a, &b, &op, &c, &d)) { 13 | int e = b/gcd(b, d)*d; 14 | a *= e/b; c *= e/d; 15 | if(op=='+') a += c; 16 | else a -= c; 17 | int f = gcd(a, e); 18 | a /= f; e /= f; 19 | if(e<0) {e *= -1; a *= -1;} 20 | if(0==a%e) printf("%d\n", a/e); 21 | else printf("%d/%d\n", a, e); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/1061/13724987_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int x, y, m, n, l; 5 | int cnt; 6 | 7 | while(scanf("%d%d%d%d%d", &x, &y, &m, &n, &l)!=EOF){ 8 | cnt = 0; 9 | if(x!=y && m==n){ 10 | printf("Impossible\n"); 11 | continue; 12 | } 13 | while(x!=y){ 14 | x += m; 15 | if(x>=l) x%=l; 16 | y += n; 17 | if(y>=l) y%=l; 18 | cnt ++; 19 | if(cnt==99999){ 20 | printf("Impossible\n"); 21 | break; 22 | } 23 | } 24 | if(cnt!=99999) printf("%d\n", cnt); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/1083/14260736_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int arr[500]; 5 | 6 | int main() 7 | { 8 | int T, a, b, i, N; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | memset(arr, 0, sizeof(arr)); 13 | scanf("%d", &N); 14 | while(N--) { 15 | scanf("%d%d", &a, &b); 16 | for(i=a; i<=b; i++) arr[i]++; 17 | } 18 | int maxn = 0; 19 | for(i=0; i<=400; i++) 20 | if(arr[i]>maxn) maxn = arr[i]; 21 | printf("%d\n", maxn*10); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/1061/13724988_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int x, y, m, n, l; 5 | int cnt; 6 | 7 | while(scanf("%d%d%d%d%d", &x, &y, &m, &n, &l)!=EOF){ 8 | cnt = 0; 9 | if(x!=y && m==n){ 10 | printf("Impossible\n"); 11 | continue; 12 | } 13 | while(x!=y){ 14 | x += m; 15 | if(x>=l) x%=l; 16 | y += n; 17 | if(y>=l) y%=l; 18 | cnt ++; 19 | if(cnt==999999){ 20 | printf("Impossible\n"); 21 | break; 22 | } 23 | } 24 | if(cnt!=99999) printf("%d\n", cnt); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/1061/13724989_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int x, y, m, n, l; 5 | int cnt; 6 | 7 | while(scanf("%d%d%d%d%d", &x, &y, &m, &n, &l)!=EOF){ 8 | cnt = 0; 9 | if(x!=y && m==n){ 10 | printf("Impossible\n"); 11 | continue; 12 | } 13 | while(x!=y){ 14 | x += m; 15 | if(x>=l) x%=l; 16 | y += n; 17 | if(y>=l) y%=l; 18 | cnt ++; 19 | if(cnt==9999999){ 20 | printf("Impossible\n"); 21 | break; 22 | } 23 | } 24 | if(cnt!=99999) printf("%d\n", cnt); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/1218/13943396_AC_0MS_132K.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int lst[200], cell[200], cnt, n, spc, i, nCase; 7 | memset(lst, 0, sizeof(lst)); 8 | for(n=5; n<=100; n++){ 9 | memset(cell, 0, sizeof(cell)); 10 | for(spc=1; spc<=n; spc++){ 11 | for(i=spc; i<=n; i+=spc){ 12 | cell[i]++; 13 | } 14 | } 15 | for(i=1, cnt=0; i<=n; i++){ 16 | if(cell[i]%2) cnt++; 17 | } 18 | lst[n] = cnt; 19 | } 20 | scanf("%d", &nCase); 21 | while(nCase--){ 22 | scanf("%d", &i); 23 | printf("%d\n", lst[i]); 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /poj-cpp/1450/14923685_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, M; 9 | 10 | int main() 11 | { 12 | int T; 13 | scanf("%d", &T); 14 | for(int nC=1; nC<=T; nC++) { 15 | scanf("%d%d", &N, &M); 16 | double ans = 0; 17 | if(0==N%2 || 0==M%2) ans = N*M; 18 | else { 19 | int n = N 2 | 3 | int N, M, cnt; 4 | 5 | int solve(int s, int n, int m); 6 | 7 | int main(){ 8 | int T; 9 | scanf("%d", &T); 10 | while(T--){ 11 | scanf("%d%d", &N, &M); 12 | cnt = 0; 13 | solve(0, N, M); 14 | printf("%d\n", cnt); 15 | } 16 | 17 | return 0; 18 | } 19 | 20 | int solve(int s, int n, int m){ 21 | int i; 22 | 23 | if(m==1 && n>=s){ 24 | cnt++; 25 | } 26 | else{ 27 | for(i=0; i<=n; i++){ 28 | if(i 2 | 3 | int N, M, cnt; 4 | 5 | int solve(int s, int n, int m); 6 | 7 | int main(){ 8 | int T; 9 | scanf("%d", &T); 10 | while(T--){ 11 | scanf("%d%d", &N, &M); 12 | cnt = 0; 13 | solve(0, N, M); 14 | printf("%d\n", cnt); 15 | } 16 | 17 | return 0; 18 | } 19 | 20 | int solve(int s, int n, int m){ 21 | int i; 22 | 23 | if(m==1 && n>=s){ 24 | cnt++; 25 | } 26 | else{ 27 | for(i=0; i<=n; i++){ 28 | if(i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | priority_queue pq; 10 | int N, i; 11 | double t, t1, t2, ans=0; 12 | 13 | scanf("%d", &N); 14 | for(i=0; i 2 | 3 | struct Point { 4 | double x, y; 5 | Point(double a, double b): 6 | x(a), y(b) {} 7 | Point() {} 8 | Point operator + (Point A) { 9 | return Point(x+A.x, y+A.y); 10 | } 11 | }; 12 | 13 | double a, b, c, d; 14 | 15 | int main() 16 | { 17 | while(~scanf("%lf%lf%lf%lf", &a, &b, &c, &d)) { 18 | Point pa = Point(a-c, b-d); 19 | scanf("%lf%lf%lf%lf", &a, &b, &c, &d); 20 | Point pb = Point(c-a, d-b); 21 | Point pc = pa+pb; 22 | printf("%.3lf %.3lf\n", a+pc.x, b+pc.y); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/3253/13917281_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct cmp{ 7 | int operator ()(int a, int b){ 8 | return a>b; 9 | } 10 | }; 11 | 12 | int main(){ 13 | priority_queue, cmp> pq; 14 | int N, t, i, cnt; 15 | 16 | scanf("%d", &N); 17 | for(i=0; i1){ 23 | t = pq.top(); 24 | pq.pop(); 25 | t += pq.top(); 26 | pq.pop(); 27 | cnt += t; 28 | pq.push(t); 29 | } 30 | printf("%d\n", cnt); 31 | 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /poj-cpp/1064/14720367_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int maxn = 10005; 4 | const int INF = 0x3f3f3f3f; 5 | int N, K; 6 | double len[maxn]; 7 | 8 | int is_ok(double d) 9 | { 10 | int cnt = 0; 11 | for(int i=0; i= K; 14 | } 15 | 16 | int main() 17 | { 18 | scanf("%d%d", &N, &K); 19 | for(int i=0; i0.001) { 23 | double m = (l+r) / 2; 24 | if(is_ok(m)) l = m; 25 | else r = m; 26 | } 27 | printf("%.2f\n", l); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /poj-cpp/1519/14264327_AC_0MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, sum, i; 6 | char str[3000]; 7 | 8 | while(scanf("%s", &str)) { 9 | if(str[0]=='0') break; 10 | n = 0; 11 | for(i=0; str[i]!='\0'; i++) n += str[i]-'0'; 12 | while(n>9) { 13 | sum = 0; 14 | while(n/10) { 15 | sum += n%10; 16 | n /= 10; 17 | } 18 | n += sum; 19 | } 20 | printf("%d\n", n); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/3181/14210927_WA.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int arr[1024][128], ans; 6 | 7 | int dfs(int n, int k); 8 | 9 | int main() 10 | { 11 | int N, K, i; 12 | 13 | memset(arr, 0, sizeof(arr)); 14 | ans = 0; 15 | scanf("%d%d", &N, &K); 16 | dfs(N, K); 17 | printf("%d\n", ans); 18 | 19 | return 0; 20 | } 21 | 22 | int dfs(int n, int k) 23 | { 24 | if(n==0) return ans += 1; 25 | else if(k==0) return 0; 26 | else if(arr[n][k]) return arr[n][k]; 27 | else if(k>n) return arr[n][k] = dfs(n, n); 28 | else { 29 | for(int i=0; n-k*i>=0; i++) { 30 | ///printf("%d ", n-k*i); 31 | arr[n][k] = dfs(n-k*i, k-1); 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /poj-cpp/3619/14813824_AC_47MS_356K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int N, K; 6 | int s, t, r; 7 | 8 | scanf("%d%d", &N, &K); 9 | while(K--) { 10 | int cnt = N; 11 | scanf("%d%d%d", &s, &t, &r); 12 | int n = cnt / (s*t); 13 | int ans = n*(t+r); 14 | cnt %= s*t; 15 | if(!cnt) { 16 | ans -= r; 17 | } else { 18 | n = cnt / s; 19 | ans += n; 20 | if(cnt%s) ans++; 21 | } 22 | printf("%d\n", ans); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/1061/13873403_WA.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int gcd(int a, int b){ 6 | if(!b) return a; 7 | else return gcd(b, a%b); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a*b/gcd(a, b); 12 | } 13 | 14 | 15 | int main(){ 16 | int x, y, a, b, L, n, i; 17 | 18 | while(~scanf("%d%d%d%d%d", &x, &y, &a, &b, &L)){ 19 | 20 | x %= L; y %= L; a %= L; b %= L; 21 | if(x==y){ 22 | printf("0\n"); 23 | continue; 24 | } 25 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 26 | for(i=1; i<=n; i++){ 27 | if( (x+a*i)%L == (y+b*i)%L ) break; 28 | } 29 | if(i==n+1) printf("Impossible\n"); 30 | else printf("%d\n", i); 31 | 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /poj-cpp/1064/14720369_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int maxn = 10005; 4 | const int INF = 0x3f3f3f3f; 5 | int N, K; 6 | double len[maxn]; 7 | 8 | int is_ok(double d) 9 | { 10 | int cnt = 0; 11 | for(int i=0; i= K; 14 | } 15 | 16 | int main() 17 | { 18 | scanf("%d%d", &N, &K); 19 | for(int i=0; i0.0001) { 23 | double m = (l+r) / 2; 24 | if(is_ok(m)) l = m; 25 | else r = m; 26 | } 27 | printf("%.2f\n", l); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /poj-cpp/1183/14818759_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int INF = 0x3f3f3f3f3f3f3f3f; 5 | 6 | int main() 7 | { 8 | long long a, b, c; 9 | 10 | while(~scanf("%lld", &a)) { 11 | long long ans = INF; 12 | for(b=1; ; b++) { 13 | if(a!=b && 0==(a*b+1)%(b-a)) { 14 | c = (a*b+1)/(b-a); 15 | if(c<0) continue; 16 | if(b+cc) break; 18 | } 19 | } 20 | printf("%lld\n", ans); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/1528/14795278_AC_0MS_628K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int maxn = 70000; 4 | int arr[maxn]; 5 | 6 | int solve() 7 | { 8 | for(int i=1; iarr[n]) printf("DEFICIENT\n"); 22 | else if(n 2 | 3 | const int maxn = 1e6+1; 4 | int fact[maxn], prime[maxn]; 5 | long long dp[maxn]; 6 | 7 | void sieve() 8 | { 9 | 10 | for(int i=2; i*2 2 | 3 | const int maxn = 1e6+1; 4 | int fact[maxn], prime[maxn]; 5 | long long dp[maxn]; 6 | 7 | void sieve() 8 | { 9 | for(int i=2; i 2 | 3 | char num[1000010]; 4 | int N; 5 | 6 | int main() 7 | { 8 | int i, a, b; 9 | 10 | scanf("%d", &N); 11 | for(i=0; i0; i--) { 19 | if(num[i]>'9') { 20 | num[i] -= 10; 21 | num[i-1] += 1; 22 | } 23 | } 24 | if(num[0]>'9') { 25 | num[0] -= 10; 26 | putchar('1'); 27 | } printf("%s\n", num); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /poj-cpp/1326/14771129_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char t1[30], t2[30], type[10]; 6 | int m, ans = 0; 7 | 8 | while(scanf("%s", t1)) { 9 | if(t1[0]=='0') { 10 | printf("%d\n", ans); 11 | ans = 0; 12 | continue; 13 | } else if(t1[0]=='#') break; 14 | scanf("%s%d%s", t2, &m, type); 15 | int t = 0; 16 | if(type[0]=='F') t = m*2; 17 | else if(type[0]=='B') t = (int)(m*1.5+0.5); 18 | else t = m; 19 | if(t<500) t = 500; 20 | ans += t; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /poj-cpp/1663/14366244_AC_16MS_132K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x, y, T; 6 | 7 | scanf("%d", &T); 8 | while(T--) { 9 | scanf("%d%d", &x, &y); 10 | if(x-y!=0 && x-y!=2) printf("No Number\n"); 11 | else { 12 | if(x==y) { 13 | if(x&1) printf("%d\n", x*2-1); 14 | else printf("%d\n", x*2); 15 | } else { 16 | if(x&1) printf("%d\n", x*2-3); 17 | else printf("%d\n", x*2-2); 18 | } 19 | } 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /poj-cpp/2503/13929195_AC_844MS_10488K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef char String[15]; 8 | 9 | int main(){ 10 | map mp; 11 | char str1[15], str2[15], str[15]; 12 | char tch; 13 | 14 | scanf("%s%s", str1, str2); 15 | mp[str2] = str1; 16 | while(1){ 17 | if(getchar()=='\n' && (tch=getchar())=='\n') break; 18 | str1[0] = tch; 19 | scanf("%s%s", &str1[1], str2); 20 | mp[str2] = str1; 21 | } 22 | 23 | while(~scanf("%s", str)){ 24 | if(mp[str].empty()) printf("eh\n"); 25 | else printf("%s\n", mp[str].c_str()); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /poj-cpp/1833/14245556_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T, n, k, i, arr[1050]; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d%d", &n, &k); 13 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | double hei[1024], g[1024]; 8 | 9 | int cmp(double a, double b) 10 | { 11 | return a > b; 12 | } 13 | 14 | int main() 15 | { 16 | int N; 17 | scanf("%d", &N); 18 | for(int i=0; ians) ans = r; 27 | } 28 | printf("%d\n", N-ans-2); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /poj-cpp/2533/13923581_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | int num[2000], sub[2000], i, j, maxs, N; 6 | 7 | while(~scanf("%d", &N)){ 8 | for(i=0; i=0; j--){ 14 | if(num[j]maxs) maxs = sub[i]; 22 | } 23 | printf("%d\n", maxs); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2533/13923608_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | int num[2000], sub[2000], i, j, maxs, N; 6 | 7 | while(~scanf("%d", &N)){ 8 | for(i=0; i=0; j--){ 14 | if(num[j]<=num[i]){ 15 | sub[i] = sub[j]+1; 16 | break; 17 | } 18 | } 19 | } 20 | for(i=0, maxs=0; imaxs) maxs = sub[i]; 22 | } 23 | printf("%d\n", maxs); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/2533/13923613_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | int num[2000], sub[2000], i, j, maxs, N; 6 | 7 | while(~scanf("%d", &N)){ 8 | for(i=0; i=0; j--){ 14 | if(num[j]maxs) maxs = sub[i]; 22 | } 23 | printf("%d\n", maxs); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /poj-cpp/3253/13917288_AC_32MS_356K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct cmp{ 7 | int operator ()(int a, int b){ 8 | return a>b; 9 | } 10 | }; 11 | 12 | int main(){ 13 | priority_queue, cmp> pq; 14 | int t; 15 | long long N, i, cnt; 16 | 17 | scanf("%lld", &N); 18 | for(i=0; i1){ 24 | t = pq.top(); 25 | pq.pop(); 26 | t += pq.top(); 27 | pq.pop(); 28 | cnt += t; 29 | pq.push(t); 30 | } 31 | printf("%lld\n", cnt); 32 | 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /poj-cpp/3589/14253716_AC_0MS_160K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char n1[5], n2[5]; 6 | int i, j, ca, cb, T; 7 | 8 | scanf("%d", &T); 9 | while(T--) { 10 | scanf("%s%s", n1, n2); 11 | ca = cb = 0; 12 | for(i=0; i<4; i++) if(n1[i]==n2[i]) ca++; 13 | for(i=0; i<4; i++) 14 | for(j=0; j<4; j++) 15 | if(n1[i]==n2[j]) { 16 | cb++; 17 | n2[j] = '*'; 18 | } 19 | printf("%dA%dB\n", ca, cb-ca); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /poj-cpp/1338/14819111_MLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 10000000; 7 | int arr[2][maxn], ans[maxn], lc, rc, l, r, n; 8 | 9 | int main() 10 | { 11 | arr[0][0] = 3; arr[1][0] = 4; 12 | ans[0] = 1; int cnt = 1; 13 | lc = rc = 1; l = r = 0; 14 | while(cnt 2 | #include 3 | #include 4 | 5 | int arr[1000001]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(10000000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", arr[n]+1); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | double t, prev = 0; 28 | 29 | for(i=1; i<=n; i++) { 30 | t = log10(i)+prev; 31 | arr[i] = t; 32 | prev = t; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /poj-cpp/1833/14245538_TLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T, n, k, i, arr[1050]; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d%d", &n, &k); 13 | for(i=0; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T, n, k, i, arr[1050]; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d%d", &n, &k); 13 | for(i=0; i 2 | 3 | int get_n(char *str); 4 | 5 | int main() 6 | { 7 | int N, i; 8 | char str[50]; 9 | 10 | scanf("%d", &N); 11 | while(N--) { 12 | scanf("%s", str); 13 | printf("%d", get_n(str)); 14 | for(i=8; i<32; i+=8) { 15 | printf(".%d", get_n(str+i)); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | int get_n(char *str) 24 | { 25 | int i, sum; 26 | 27 | for(i=0, sum=0; i<8; i++) { 28 | sum += (1<<(7-i))*(str[i]-'0'); 29 | } 30 | 31 | return sum; 32 | } 33 | -------------------------------------------------------------------------------- /poj-cpp/2387/14392052_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int T, E, N, d[1100], u[4100], v[4100], w[4100]; 4 | 5 | int Bellman() 6 | { 7 | int update = 1; 8 | for(int i=1; i<=N; i++) d[i] = 99999999; 9 | d[1] = 0; 10 | while(update) { 11 | update = 0; 12 | for(int i=0; i d[u[i]] + w[i]) { 14 | d[v[i]] = d[u[i]] + w[i]; 15 | update = 1; 16 | } 17 | } 18 | } 19 | return d[N]; 20 | } 21 | 22 | int main() 23 | { 24 | int tu, tv, tw; 25 | 26 | scanf("%d%d", &T, &N); 27 | E = 0; 28 | while(T--) { 29 | scanf("%d%d%d", &tu, &tv, &tw); 30 | u[E] = tu; v[E] = tv; 31 | w[E] = tw; E++; 32 | //u[E] = tv; v[E] = tu; 33 | //w[E] = tw; E++; 34 | } 35 | printf("%d\n", Bellman()); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /poj-cpp/2591/14819113_MLE.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | const int maxn = 10000000; 7 | int arr[2][maxn], ans[maxn], lc, rc, l, r, n; 8 | 9 | int main() 10 | { 11 | arr[0][0] = 3; arr[1][0] = 4; 12 | ans[0] = 1; int cnt = 1; 13 | lc = rc = 1; l = r = 0; 14 | while(cnt 2 | #include 3 | 4 | char str[2048]; 5 | 6 | int judge(int s, int t) 7 | { 8 | while(s<=t && str[s]==str[t]) { 9 | s++; t--; 10 | } 11 | return str[s]str[s]) { 30 | putchar(str[t]); 31 | t--; 32 | } else { 33 | if(judge(s, t)) { 34 | putchar(str[s]); 35 | s++; 36 | } else { 37 | putchar(str[t]); 38 | t--; 39 | } 40 | } 41 | } 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /poj-cpp/1064/14720370_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int maxn = 10005; 5 | const int INF = 0x3f3f3f3f; 6 | int N, K; 7 | double len[maxn]; 8 | 9 | int is_ok(double d) 10 | { 11 | int cnt = 0; 12 | for(int i=0; i= K; 15 | } 16 | 17 | int main() 18 | { 19 | scanf("%d%d", &N, &K); 20 | for(int i=0; i0.0001) { 24 | double m = (l+r) / 2; 25 | if(is_ok(m)) l = m; 26 | else r = m; 27 | } 28 | printf("%.2f\n", l); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /poj-cpp/1207/13860487_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int num[80000000]; 5 | 6 | void getnum(); 7 | 8 | int main(){ 9 | int s, e, i, max; 10 | 11 | getnum(); 12 | while(~scanf("%d%d", &s, &e)){ 13 | for(i=s, max=0; i<=e; i++){ 14 | if(num[i]>max) max = num[i]; 15 | } 16 | printf("%d %d %d\n", s, e, max); 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | void getnum(){ 23 | int i, j, cnt, n; 24 | 25 | memset(num, 0, 44000); 26 | 27 | num[1] = 1; 28 | for(i=1; i<10000; i++){ 29 | n = i; 30 | cnt = 0; 31 | while(1){ 32 | if(num[n]){ 33 | num[i] = cnt+num[n]; 34 | break; 35 | } 36 | if(n%2) n = 3*n+1; 37 | else n = n/2; 38 | cnt ++; 39 | } 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /poj-cpp/1862/14710605_AC_32MS_612K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | priority_queue pq; 12 | int N; 13 | double n; 14 | 15 | scanf("%d", &N); 16 | for(int i=0; i1) { 21 | double d1 = pq.top(); 22 | pq.pop(); 23 | double d2 = pq.top(); 24 | pq.pop(); 25 | pq.push(sqrt(d1*d2)*2); 26 | } 27 | printf("%.3f\n", pq.top()); 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /poj-cpp/2387/14392069_AC_16MS_432K.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int T, E, N, d[1100], u[4100], v[4100], w[4100]; 4 | 5 | int Bellman() 6 | { 7 | int update = 1; 8 | for(int i=1; i<=N; i++) d[i] = 99999999; 9 | d[1] = 0; 10 | while(update) { 11 | update = 0; 12 | for(int i=0; i d[u[i]] + w[i]) { 14 | d[v[i]] = d[u[i]] + w[i]; 15 | update = 1; 16 | } 17 | } 18 | } 19 | return d[N]; 20 | } 21 | 22 | int main() 23 | { 24 | int tu, tv, tw; 25 | 26 | scanf("%d%d", &T, &N); 27 | E = 0; 28 | while(T--) { 29 | scanf("%d%d%d", &tu, &tv, &tw); 30 | u[E] = tu; v[E] = tv; 31 | w[E] = tw; E++; 32 | u[E] = tv; v[E] = tu; 33 | w[E] = tw; E++; 34 | } 35 | printf("%d\n", Bellman()); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /poj-cpp/2602/14333999_WA.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char num[1000010], N; 4 | 5 | int main() 6 | { 7 | int i, a, b; 8 | 9 | scanf("%d", &N); 10 | for(i=0; i0; i--) { 18 | if(num[i]>'9') { 19 | num[i] -= 10; 20 | num[i-1] += 1; 21 | } 22 | } 23 | if(num[0]>'9') { 24 | num[0] -= 10; 25 | putchar('1'); 26 | } 27 | printf("%s\n", num); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /poj-cpp/3093/13929222_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[150000], cnt[150000], N, i, j, maxs; 9 | 10 | while(~scanf("%d", &N)){ 11 | for(i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | int num[150000], cnt[150000], N, i, j, maxs; 9 | 10 | while(~scanf("%d", &N)){ 11 | for(i=0; i 2 | #include 3 | 4 | int arr[500]; 5 | 6 | int main() 7 | { 8 | int T, a, b, i, N; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | memset(arr, 0, sizeof(arr)); 13 | scanf("%d", &N); 14 | while(N--) { 15 | scanf("%d%d", &a, &b); 16 | if(a>b) a^=b^=a^=b; 17 | for(i=a; i<=b; i++) arr[i]++; 18 | } 19 | int maxn = 0; 20 | for(i=0; i<=400; i++) 21 | if(arr[i]>maxn) maxn = arr[i]; 22 | printf("%d\n", maxn*10); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /poj-cpp/1207/13860812_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int num[80000000]; 5 | 6 | void getnum(); 7 | 8 | int main(){ 9 | int s, e, i, max; 10 | 11 | getnum(); 12 | while(~scanf("%d%d", &s, &e)){ 13 | for(i=s, max=0; i<=e; i++){ 14 | if(num[i]>max) max = num[i]; 15 | } 16 | printf("%d %d %d\n", s, e, max); 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | void getnum(){ 23 | int i, j, cnt, n; 24 | 25 | memset(num, 0, 44000); 26 | 27 | num[1] = 1; 28 | for(i=1; i<11000; i++){ 29 | n = i; 30 | cnt = 0; 31 | while(1){ 32 | if(num[n]){ 33 | num[i] = cnt+num[n]; 34 | break; 35 | } 36 | if(n%2) n = 3*n+1; 37 | else n = n/2; 38 | cnt ++; 39 | } 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /poj-cpp/1316/13997622_TLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, j, sum, faild; 6 | 7 | for(i=1; i<=10000; i++){ 8 | faild = 0; 9 | for(j=1; j0){ 13 | sum += t%10; 14 | t /= 10; 15 | } 16 | if(sum==i){ 17 | faild = 1; 18 | break; 19 | } 20 | } 21 | if(!faild) printf("%d\n", i); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /poj-cpp/1833/14245636_WA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T, n, k, i, arr[1050]; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d%d", &n, &k); 13 | for(i=0; i 2 | #include 3 | 4 | const int maxn = 11; 5 | 6 | int dp[maxn][maxn][1< 2 | #include 3 | #include 4 | 5 | int arr[10000001]; 6 | 7 | int solve(int n); 8 | 9 | int main() 10 | { 11 | int T, n; 12 | 13 | scanf("%d", &T); 14 | memset(arr, 0, sizeof(arr)); 15 | solve(10000000); 16 | while(T--) { 17 | scanf("%d", &n); 18 | printf("%d\n", arr[n]+1); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int solve(int n) 25 | { 26 | int ans, i; 27 | double t, prev = 0; 28 | 29 | for(i=1; i<=n; i++) { 30 | t = log10(i)+prev; 31 | arr[i] = t; 32 | prev = t; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /poj-cpp/1833/14245873_AC_469MS_136K.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T, n, k, i, arr[1050]; 9 | 10 | scanf("%d", &T); 11 | while(T--) { 12 | scanf("%d%d", &n, &k); 13 | for(i=0; i 2 | #include 3 | 4 | int N, dp[3][31][8]; 5 | 6 | int dfs(int r, int c, int s) 7 | { 8 | if(c==N) return 1; 9 | if(r==3) return dfs(0, c+1, s); 10 | if(dp[r][c][s]) return dp[r][c][s]; 11 | if(s & 1< 2 | 3 | int main() 4 | { 5 | int arr[6]; 6 | 7 | while(1) { 8 | int maxs = 0; 9 | int mins = 0x3f3f3f3f; 10 | int sum = 0; 11 | for(int i=0; i<6; i++) { 12 | scanf("%d", &arr[i]); 13 | if(arr[i]>maxs) maxs = arr[i]; 14 | if(arr[i] 2 | 3 | 4 | long long gcd(long long a, long long b){ 5 | if(!b) return a; 6 | else return gcd(b, a%b); 7 | } 8 | 9 | long long lcm(long long a, long long b){ 10 | return a*b/gcd(a, b); 11 | } 12 | 13 | 14 | int main(){ 15 | long long x, y, a, b, L, n, i; 16 | 17 | while(~scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &L)){ 18 | 19 | x %= L; y %= L; a %= L; b %= L; 20 | if(x==y){ 21 | printf("0\n"); 22 | continue; 23 | } 24 | n = lcm(L/gcd(L, a), L/gcd(L, b)); 25 | for(i=1; i<=n; i++){ 26 | if( (x+a*i)%L == (y+b*i)%L ) break; 27 | } 28 | if(i==n+1) printf("Impossible\n"); 29 | else printf("%lld\n", i); 30 | 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /poj-cpp/1157/14296209_WA.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int maps[110][110], dp[110][110], F, V; 8 | 9 | int main() 10 | { 11 | int i, j; 12 | 13 | scanf("%d%d", &F, &V); 14 | for(i=1; i<=F; i++) { 15 | for(j=1; j<=V; j++) { 16 | scanf("%d", &maps[i][j]); 17 | } 18 | } 19 | memset(dp, 0, sizeof(dp)); 20 | for(i=1; i<=F; i++) dp[i][i] = dp[i-1][i-1]+maps[i][i]; 21 | for(i=1; i<=F; i++) { 22 | for(j=i+1; j<=V; j++) { 23 | dp[i][j] = max(dp[i][j-1], dp[i-1][j-1]+maps[i][j]); 24 | } 25 | } 26 | for(i=1; i<=F; i++) { 27 | for(j=1; j<=V; j++) printf("%d ", dp[i][j]); 28 | printf("\n"); 29 | } 30 | printf("%d\n", dp[F][V]); 31 | 32 | return 0; 33 | } --------------------------------------------------------------------------------