一、基本常识
一、不同返回结果:
1、Accepted(答案正确)
2、Wrong Answer(答案错误) 解决方案:(1)如果对设计算法正确性有较大的把握,可以考虑是否是存在某些特殊数据导致错误。
3、Presentation Error(格式错误)系统判定你的程序输出“好像”正确,只是没有按照题目中所要求的输出格式来输出答案。可 能因为多输出了一些空格、换行之类的多余字符。
4、Time Limit Exceeded(超出时间限制):超出时间限制。
二、技巧:
1、c++的算法库:
<algorithm>
(1)sort(a,a+n,func)
func定义排序的规则,应用的是快排算法。
2、输入技巧:
scanf("%4d%2d%2d",&a,&b,&c);
可以将一个输入取前面的4位给a,取前面的2位给b,取前面的2位给c。
三、日期类问题:
解决思想:把原区间问题统一到起点确定的区间问题上去。这样可以做到预处理。
求两个日期的天数之差:

1 #include<iostream> 2 using namespace std; 3 //判断是不是闰年 4 #define isyeap(x) x%100!=0 && x%4==0 || x%400 == 0?1:0 5 6 int dayofmonth[13][2]={ 7 0,0, 8 31,31, 9 29,28, 10 31,31, 11 30,30, 12 31,31, 13 30,30, 14 31,31, 15 31,31, 16 30,30, 17 31,31, 18 30,30, 19 31,31 20 }; 21 struct Date{ 22 int day; 23 int month; 24 int year; 25 void nextday(){ 26 day++; 27 if(day>dayofmonth[month][isyeap(year)]){ 28 day=1; 29 month++; 30 if(month>12){ 31 month=1; 32 year++; 33 } 34 35 } 36 } 37 }; 38 int a[5000][13][32]; 39 int main(){ 40 Date tmp; 41 int cnt=0; 42 tmp.day=1; 43 tmp.month=0; 44 tmp.year=0; 45 while(tmp.year<5000){ 46 a[tmp.year][tmp.month][tmp.day]=cnt; 47 tmp.nextday(); 48 cnt++; 49 } 50 51 Date t1,t2; 52 scanf("%4d%2d%2d",&t1.year,&t1.month,&t1.day); 53 scanf("%4d%2d%2d",&t2.year,&t2.month,&t2.day); 54 printf("%d",a[t2.year][t2.month][t2.day]-a[t1.year][t1.month][t1.day]+1); 55 56 57 58 59 60 }
如果求的是给定日期的周几:
可以先求给定日期和今天的天数之差,然后模7,然后和
四、哈希应用:
求解此类问题,共同点是:输入的分数种类是有限的,主要是输入数据要给定范围。
例题:求解某一成绩在所有成绩中出现的频度。
五、查找:
一般如果在查找中时间超限可以考虑用二分查找来解决。
六、贪心算法:
思想:每次选择当前最后的选择,一般用于求最优值问题。
缺点:有时候只能求出局部的最优解。