- 在线时间
- 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- f% O3 m7 Z% i0 f2 k* u8 m
% B1 K' j- N8 w0 S* a. d
在本地VC6.0下测试,得出正确结果, 为什么提交后总是Wrong Answer' X5 H0 |9 e( `6 z2 m+ j
. r7 N" _/ K& ?3 ^现将代码贴出,请帮忙看看:
, d5 a3 t% h$ q1 r - #include <iostream> h; V7 D$ z: F M6 } ~6 H$ @
- using namespace std;
- - l- A. h o Q\\" e9 T8 ^
- #define PH 0, Y1 o\\" o8 w: k u+ W+ `. F& _ T
- #define EM 1$ j: T$ E' @0 H! L% u: C
- #define IN 2
- 0 y: r, I J0 @: D' ?
- int get_Top(int days, int kind);
- ( F* Y4 O) c+ O f- R: ?+ R$ D
- int triple(int ptop, int etop, int itop, int cur);6 |9 @5 k$ s4 M& {$ j; c
- bool is_Integer(float n);) J; j4 F) w9 I: C+ C) N8 g& ?
- int main()/ p' m1 a0 e( u
- {
- ' `( ]8 l& N0 v( Z y5 w3 R1 [1 T
- int ptop, etop, itop;( Y/ p5 G/ E+ f L\\" f; A
- int pdays, edays, idays, curdays;/ [- N6 ]\\" b8 H- l* Z: X# v; ~
- int count =0;; q6 ^5 s\\" B: d
- 1 ^8 n: J) h0 n, v% G5 F3 X4 {
- while(cin >> pdays >> edays >> idays >> curdays)6 A; t8 H0 b d# z: `3 F- J u
- {
- 5 s, P& m2 v\\" Q1 c. n
- if(pdays==edays&&pdays==idays&&pdays==curdays&&pdays==-1), [3 _* r0 M% |5 z( i
- break;
- 8 a7 ~\\" r! g8 B
- count++;) R* ]# R* \. Y; S0 V* c: Z) @9 w- m k7 \
- ptop = get_Top(pdays,PH);
- . w/ x# Y; {( L5 _, T
- etop = get_Top(edays,EM);
- , i0 d; I* X0 g. a
- itop = get_Top(idays,IN);
- ( U' b) b* X5 R! {) M. E' _+ l9 u, ?
- cout<<"Case "<<count<<": "<<"the next triple peak occurs in "<<triple(ptop, etop, itop, curdays)<<" days.";% P* J0 U% G; i3 V: q' o
- }! K4 w& C& A% h9 f9 y
-
- ! v D; _4 f; z2 d) r$ V# h/ _# e
- return 0;
- 1 b5 }+ o$ s\\" {
- }
- 8 j1 j5 m8 V\\" N1 W
- int get_Top(int days, int kind)
- 5 ~7 O+ X; X: a# ]; ~6 u2 T
- {. A k; _. f5 w5 n
- switch(kind)
- 6 u3 C8 Z7 L6 Y5 v5 x, P
- {% A% G3 g, b1 r! w, j6 \
- case 0:
- ! Z- q1 T0 h0 A7 {% j
- return days%23;! R# O f! t+ e! N) a7 l* [0 r
- case 1:5 p9 R: d: O8 `0 d- f' O* E
- return days%28;
- 5 [3 s4 {8 C' \3 V: o( g
- case 2:
- 2 k/ s, k$ f1 ?2 X/ ?7 h: E
- return days%33;
- ; j, g4 F. v) [( E
- }
- & O0 _8 J! \7 Y* W( a
- return 0;
- * H6 q1 f4 b! u) m% ~
- }) S/ r2 V\\" T3 h/ C5 L R
- & e! }7 t* ?3 \5 O( F8 H
- int triple(int ptop, int etop, int itop, int cur)
- # }& W6 S- |7 r, P1 ]/ ]: i2 h
- {
- ! M% N& h$ }/ M5 W( s
- float x, y, z;( _5 t5 T0 k5 ?& x
- int m1 = etop-ptop-5,5 @0 I0 I- }( U! `
- m2 = itop-etop-5;# z( v( S6 u- R# g! ~% ^) g
- int temp = 0;, \5 C) n& s\\" |9 C
- for(z=2; (itop+(z-1)*33) <= 21252; z++)# I( J3 V; B4 X7 X- c
- {
- / Y& Q z! n/ z- Q# P& R- f) N
- temp = m2 + 33*z;$ e7 a! l5 R) Q$ _6 R
- y = (float)temp/28;& F r5 N! t\\" M4 M5 v# p* c: Y1 P
- x = (float)(m1+temp)/23;0 b7 r6 j9 o\\" d
- if(x>0 && y>0 && is_Integer(x) && is_Integer(y))
- 3 j9 B/ [\\" s' t' O) j* H$ u
- return itop + (z-1)*33 -cur;
- & K5 t+ ^9 Z7 y2 Z1 d. _ m
- }& g\\" Z. ]( r2 Y\\" V
- return 0;
- ! k: W7 F4 W+ d& b9 z
- }
- - X( s, n1 }\\" c& O
- ) V6 v\\" v5 M+ F
- bool is_Integer(float n)
- ) b1 t( s* j6 {' `& H/ F: r
- {
- . X\\" v L9 h; r! M% e
- if( (int)n - n ==0)0 V; L) c8 V9 A9 K2 j4 T
- return true;
- # e+ M9 O! K, A$ f2 Q* @' ?3 y/ Y
- else\\" W# t% E+ G% N8 h E
- return false;6 o0 K0 F* C! h$ h6 B' ^: y; H
- } s* e& |5 V: [\\" W' y+ |% Z; X
- - N7 |- ^5 k3 w; k' d3 x# {* z5 ~
4 Z; h, e0 a/ Z9 {7 b
|
zan
|