POJ 2712 细菌繁殖 解题报告
POJ 2712 细菌繁殖 解题报告
编号:2712
考查点:日期和时间处理
思路:抽象出num*2^day即可,然后想到每个月的天数用散列法
提交情况:一次AC,不过测试的时候错了一个符号..
Source Code:
#include <iostream>
using namespace std;
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int n;
cin>>n;
for (int k=0;k<n;k++)
{
int mon1,mon2;
int day1,day2;
int num,day=0;
int key = 2;
cin>>mon1>>day1;
cin>>num;
cin>>mon2>>day2;
for (int i=mon1-1;i<mon2-1;i++)
{
day += month[i];
}
day += day2 - day1;
for (int i=1;i<day;i++)
{
key <<= 1;
}
cout<<num*key<<endl;
}
return 0;
}
using namespace std;
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int n;
cin>>n;
for (int k=0;k<n;k++)
{
int mon1,mon2;
int day1,day2;
int num,day=0;
int key = 2;
cin>>mon1>>day1;
cin>>num;
cin>>mon2>>day2;
for (int i=mon1-1;i<mon2-1;i++)
{
day += month[i];
}
day += day2 - day1;
for (int i=1;i<day;i++)
{
key <<= 1;
}
cout<<num*key<<endl;
}
return 0;
}
总结:超级水题啊..不过发现那个散列法用空间换时间挺不错,以后继续用,呵呵
By Ns517
Time 09.01.23