题目:http://poj.org/problem?id=3393
不多说了,简单模拟题,因为粗心写错了两个字母,导致错了N遍,模拟还是一贯的恶心,代码实在不想优化了,写的难看了点。。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 const int First = 0; 5 const int Last = 1; 6 7 int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 8 int days[10010][13]; 9 int weekday[10010][13][2]; 10 11 int main() 12 { 13 for(int i = 1; i <= 10000; i++) 14 { 15 memcpy(days[i], month, sizeof(month)); 16 if( (i < 1582 && i % 4 == 0) || 17 (i > 1582 && (i % 4 == 0 && i % 100 != 0 || i % 400 == 0))) 18 { 19 days[i][2] = 29; 20 } 21 } 22 days[1700][2] = 29; 23 days[1752][9] -= 11; 24 weekday[1][1][First] = 6; 25 for(int i = 1; i <= 10000; i++) 26 { 27 for(int j = 1; j <= 12; j++) 28 { 29 weekday[i][j][Last] = (weekday[i][j][First] + days[i][j] - 1) % 7; 30 if(j != 12)weekday[i][j+1][First] = (weekday[i][j][Last] + 1) % 7; 31 else weekday[i+1][1][First] = (weekday[i][j][Last] + 1) % 7; 32 } 33 } 34 35 int t, ys, ms, ye, me; 36 scanf("%d", &t); 37 while(t--) 38 { 39 scanf("%d %d %d %d", &ys, &ms, &ye, &me); 40 int good = 0, lucky = 0; 41 while(!(ys >= ye && ms >= me)) 42 { 43 if(weekday[ys][ms][First] == 6 || weekday[ys][ms][First] <= 1) 44 good++; 45 if(weekday[ys][ms][Last] == 0 || weekday[ys][ms][Last] >= 5) 46 lucky++; 47 if(ms++ == 13) 48 { 49 ys++; 50 ms = 1; 51 } 52 } 53 if(weekday[ye][me][First] == 6 || weekday[ye][me][First] <= 1) 54 good++; 55 if(weekday[ye][me][Last] == 0 || weekday[ye][me][Last] >= 5) 56 lucky++; 57 printf("%d %d\n", lucky, good); 58 } 59 return 0; 60 }