HDU - 4551 생일 맞 춰 봐 수학 + 매 거

14356 단어 HDU
제목 링크: http://acm.hdu.edu.cn/showproblem.php?pid=4551
물 문제 하나.
 1 //STATUS:C++_AC_15MS_232KB

 2 #include <functional>

 3 #include <algorithm>

 4 #include <iostream>

 5 //#include <ext/rope>

 6 #include <fstream>

 7 #include <sstream>

 8 #include <iomanip>

 9 #include <numeric>

10 #include <cstring>

11 #include <cassert>

12 #include <cstdio>

13 #include <string>

14 #include <vector>

15 #include <bitset>

16 #include <queue>

17 #include <stack>

18 #include <cmath>

19 #include <ctime>

20 #include <list>

21 #include <set>

22 #include <map>

23 using namespace std;

24 //define

25 #define pii pair<int,int>

26 #define mem(a,b) memset(a,b,sizeof(a))

27 #define lson l,mid,rt<<1

28 #define rson mid+1,r,rt<<1|1

29 #define PI acos(-1.0)

30 //typedef

31 typedef __int64 LL;

32 typedef unsigned __int64 ULL;

33 //const

34 const int N=2010;

35 const int INF=0x3f3f3f3f;

36 const int MOD=100000,STA=8000010;

37 const LL LNF=1LL<<60;

38 const double EPS=1e-8;

39 const double OO=1e15;

40 const int dx[4]={-1,0,1,0};

41 const int dy[4]={0,1,0,-1};

42 //Daily Use ...

43 inline int sign(double x){return (x>EPS)-(x<-EPS);}

44 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}

45 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}

46 template<class T> inline T Min(T a,T b){return a<b?a:b;}

47 template<class T> inline T Max(T a,T b){return a>b?a:b;}

48 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}

49 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}

50 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}

51 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}

52 //End

53 

54 int T,ans[N][2];

55 int d[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};

56 

57 int main()

58 {

59  //   freopen("in.txt","r",stdin);

60     int i,j,y,a,b,flag,ca=1;

61     scanf("%d",&T);

62     while(T--)

63     {

64         scanf("%d%d%d",&a,&b,&y);

65         flag= ((y%4==0 && y%100!=0) || y%400==0);

66         int k=0;

67         for(i=1;i<=12;i++){

68             for(j=1;j<=31;j++){

69                 if(gcd(i,j)==a && lcm(i,j)==b){

70                     ans[k][0]=i;

71                     ans[k++][1]=j;

72                 }

73             }

74         }

75         int cnt=0,w;

76         for(i=0;i<k;i++){

77             if(ans[i][0]!=2 && ans[i][1]<=d[ans[i][0]]){w=i;cnt++;}

78             else if(flag && ans[i][1]<=29){w=i;cnt++;}

79             else if(ans[i][1]<29){w=i;cnt++;}

80         }

81 

82         printf("Case #%d: ",ca++);

83         if(cnt==0)printf("-1
"); 84 else if(cnt==1)printf("%d/%02d/%02d
",y,ans[w][0],ans[w][1]); 85 else printf("1
"); 86 87 } 88 return 0; 89 }

좋은 웹페이지 즐겨찾기