Friday Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
It was said that the black Friday was number 13th? Let us see whether number 13th and Friday are more destined than other days.
Give non-negative n, please tell me in "January 1, 1900" to "1900+n-1 year December 31", Monday to Sunday each have how many number 13th.
Note that in the output, the order is Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, altogether 7 numbers, separated by a space.
"Data Range"
n<=400
"Input Sample"
20
"Output Example"
36 33 34 33 35 35 34
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
It's a simple procedure, with 13th numbers per month, so it's good to enumerate all the months. The process of judging the common year leap year, to ensure that the monthly days do not calculate the wrong is good.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
This question to see non-negative, I think should consider the special circumstances of the n==0, the results of the data, there is a feeling of the pit ...
This is finished by hand to WA, a look found that the output requirements are Saturday put on the first ...
After changing the hand up and WA, this time how can not be wrong, the result is to come to the Dyz AC code, found that their change function three return did not write into if the curly braces, rusty Ah!
Incidentally, my code in the n==0 of the special sentence can be omitted, and Dyz code forgot to n==0 special, exactly his code really need to n==0 of the special, can only say that the data cheap him-.-
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Code
1 /*2 id:icedrea13 Prog:friday4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten One intadd[1+ A]={0, to, -, to, -, to, -, to, to, -, to, -, to }; A -Ifstreaminch("friday.in"); -Ofstream out("Friday.out"); the - intn,r[7]; - - voidChangeinty) + { - if(y% -==0) {add[2]= in;return; } + if(y% -==0) {add[2]= -;return; } A if(y%4==0) {add[2]= in;return; } atadd[2]= -; - } - voidWork () - { -cout<<" in work"<<Endl; - intState=6; in for(inty=1900; y<=1900+n-1;++y) - { toChange (y); cout<<"y="<<y<<"\tday="<<add[2]<<Endl; + for(intm=1; m<= A;++m) - { the++r[state];//cout<< "m=" <<m<< "\tstate=" <<state; *State= (State+add[m])%7;//cout<< "\tadd=" <<add[m]<<endl; $ }Panax Notoginseng } - out<<r[6]<<' '<<r[0]<<' '<<r[1]<<' '<<r[2]<<' '<<r[3]<<' '<<r[4]<<' '<<r[5]<<Endl; the } + A intMain () the { + inch>>N; - if(n==0) { out<<"0 0 0 0 0 0 0"<<endl; }ElseWork (); $ inch. Close (); out. Close (); $ return 0; -}
Usaco Section1.1 Friday The thirteenth Problem solving report