在线时间 0 小时 最后登录 2010-11-12 注册时间 2010-8-27 听众数 3 收听数 0 能力 0 分 体力 46 点 威望 0 点 阅读权限 20 积分 16 相册 0 日志 0 记录 0 帖子 5 主题 2 精华 0 分享 0 好友 1
升级 11.58%
该用户从未签到
POJ-1006
; A |' ?0 j( @: E 3 N N% L c) i$ _
在本地VC6.0下测试,得出正确结果, 为什么提交后总是Wrong Answer
; ? t6 _5 u. l/ {6 m 4 T# D+ G8 G0 d | b
现将代码贴出,请帮忙看看:( t' I! S' Y% J* ^ #include <iostream># S) Z1 H4 l& t* y/ a\\" e: ]$ F
using namespace std;) Z4 P3 p7 j\\" d {; ?
#define PH 05 v9 w5 Z$ l! `) X v2 ^
#define EM 12 P- D* b1 Q' S* X
#define IN 2
- o$ p- t# Y$ }. g int get_Top(int days, int kind);
( b1 e7 ~\\" \! S4 B int triple(int ptop, int etop, int itop, int cur);# C4 ^( q/ ~8 N2 j! M/ [
bool is_Integer(float n);
: R! B5 E; ] }/ [ int main()
* n, T% T h) y {
6 S+ J# k; g1 b* i/ h; c' g int ptop, etop, itop;
# J* h3 h2 o) U2 Z! I5 S int pdays, edays, idays, curdays;( l3 a9 |/ T# Q! x* a# z: m
int count =0;/ c9 I5 W% K l* j1 H+ E) D! d# n
$ M% \( L: ~* I7 h, a- N2 M! u while(cin >> pdays >> edays >> idays >> curdays)' x2 ]' {6 z) @6 p; i+ G
{
+ ` X* E0 e' E5 {* M, r if(pdays==edays&&pdays==idays&&pdays==curdays&&pdays==-1)
- V2 o' u, n( _ break;
/ y6 o* p: M( P6 K6 U count++;; l1 o5 |( ?5 t4 |5 G
ptop = get_Top(pdays,PH);' d$ q# Z. }4 f6 z2 F7 p
etop = get_Top(edays,EM);; {1 [2 _\\" E3 d+ }% `7 w% }: m: X2 I: D
itop = get_Top(idays,IN);- k0 B/ [) W0 P3 ?2 B7 R
cout<<"Case "<<count<<": "<<"the next triple peak occurs in "<<triple(ptop, etop, itop, curdays)<<" days.";6 ?1 p) Q4 N V- G+ [
} p7 M\\" V( m( u5 i/ g$ p3 d
- w, A# m( M( V( ~, `# _! b
return 0;\\" ]7 [4 t) ?6 P0 N$ I
}
( @$ c0 }% C3 U/ e int get_Top(int days, int kind)
3 ^; I6 T I/ ~5 t1 Y { F- J! R' q k; ~8 g6 k
switch(kind)1 a Z0 W* d R4 x+ t. t! J
{7 ~( u( ~. h% t1 Y7 N/ w) a' t+ F
case 0:
3 [1 g5 t7 K3 f% h return days%23;6 E8 a, j: ] E: U, j' T3 g. B
case 1:! n5 Y1 p/ F8 v
return days%28;\\" K$ [+ h, L: O7 B
case 2: ?5 d, F- G2 P d& V+ k0 S2 \
return days%33;
4 |) O0 Y+ Z) T5 L* ` }5 g, @3 }* V( ~/ n4 F9 g- ]5 H) [' ]8 B
return 0;
% N, {9 C8 J+ q8 y }# Q5 n; i7 `$ F7 U, U5 P7 k4 v2 b
5 Z& ]. _\\" m7 g5 L/ C
int triple(int ptop, int etop, int itop, int cur)8 f. V% y/ R' t
{
$ d& Z* v9 e! o float x, y, z;
\\" V1 }' R& y2 H# f) v int m1 = etop-ptop-5,
+ Q$ {+ M$ {2 y L4 T5 j4 \, X1 _ m2 = itop-etop-5;\\" X0 [3 f& d5 h( h* s
int temp = 0;
6 |! R( ~, M1 E$ c6 g) f9 S G for(z=2; (itop+(z-1)*33) <= 21252; z++)9 c. `3 o; B, P6 }7 W F; r
{3 s/ Q\\" k1 x6 d5 p: t6 h
temp = m2 + 33*z;
) q\\" T- ?1 q; T [/ Q\\" j y = (float)temp/28;
) D) Y7 n. i3 U7 m# P x = (float)(m1+temp)/23;
2 C. a. `8 f# J- m8 K) V) d# _ if(x>0 && y>0 && is_Integer(x) && is_Integer(y))0 ?, D5 p/ F2 c2 Y5 J
return itop + (z-1)*33 -cur;5 S' y- ?0 p1 A7 e- H6 }$ B- v
}) |$ v/ X( m6 ^5 K' s
return 0;# [0 {5 b$ J# C\\" n4 x: \/ i
}& S3 j) r$ N) [7 ]. H' y
$ B' N- A* q2 D bool is_Integer(float n)
6 r/ X, n; D+ @( g5 K/ n {
# z: X, D( U' x5 _$ c/ z if( (int)n - n ==0); C7 G! G4 B( g) ~3 b+ n$ J+ d9 O
return true;
9 W' c; s2 F. Z\\" d2 q* C- ]\\" V1 I else2 x4 V! B* j- ^6 n) {4 f: x4 O4 M
return false;
2 S& D% V- \! t7 M6 ^ }
- P$ j- Q# ]* }\\" V 3 e. k4 M8 A/ v1 H, x% ~7 ?5 [
]8 S* [. T" y- e: d' q
zan