随笔分类 -  算法竞赛入门经典

摘要:uva 10494 - If We Were a Child AgainIf We Were a Child AgainInput:standard inputOutput:standard outputTime Limit:7seconds“Oooooooooooooooh!If I could do the easy mathematics like my school days!!I can guarantee, that I’d not make any mistake this time!!”Says a smart university student!!But his teach 阅读全文
posted @ 2013-07-13 16:00 Norcy 阅读(841) 评论(0) 推荐(0)
摘要:uva748 - ExponentiationExponentiationProblems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.This problem requires that you write a program to compute the e 阅读全文
posted @ 2013-07-12 15:05 Norcy 阅读(491) 评论(0) 推荐(0)
摘要:uva 465 - OverflowOverflowWrite a program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expression is too large to be represented as a ``normal'' signed integer (typeintegerif you are working Pascal, typeinti 阅读全文
posted @ 2013-07-12 14:23 Norcy 阅读(1001) 评论(0) 推荐(0)
摘要:/*1.高精度加法2.高精度减法 3.高精度乘法 4.高精度除以低精度 5.高精度对低精度的取余 必要时可以将全局的int替换成long long.除了main函数的返回值int用到除法和取余的时候可能需要把全局的int替换成long long */#include #include #include #include using namespace std;#define maxn 30000struct bign{ int len, s[maxn]; bign() { memset(s, 0, sizeof(s)); len = 1; }... 阅读全文
posted @ 2013-07-12 14:12 Norcy 阅读(488) 评论(0) 推荐(0)
摘要:uva 694 - The Collatz Sequence这道题值得一提的是,用int会超出运算范围,所以while里面会陷入死循环而超时。故要用long long.顺便地,int 范围差不多在 2,000,000,000 二十亿左右,看测试数据都知道超int了。/*这道题值得一提的是,用int会超出运算范围,所以while里面会陷入死循环而超时。故要用long long.顺便地,int 范围差不多在 2,000,000,000 二十亿左右,看测试数据都知道超int了。 */#include #include using namespace std;int main(){ long l... 阅读全文
posted @ 2013-07-12 02:36 Norcy 阅读(426) 评论(0) 推荐(0)
摘要:uva414 - Machined Surfaces/*水题,值得一提的是,getline使用时注意不能让它多吃回车键,处理方法可以用getchar。 */#include #include #include using namespace std;int main(){ int n; while (cin >> n, n) { getchar(); //第一个回车键会被getline拿去,所以要用getchar处理这个回车 定义在cstdio string s[n]; int blac... 阅读全文
posted @ 2013-07-11 22:50 Norcy 阅读(326) 评论(0) 推荐(0)
摘要:uva 490 - Rotating Sentences很奇葩的一个题目,题意有多不清楚我就不说了,题目很简单,但是坑很多,一个比一个大,具体可以百度之,但是……同样思路的代码别人AC了我却WA,慢慢一步一步比较之后,才发现这题目(还是uva这个古老的OJ?)的奇葩之处。网上的代码怎么尼玛的都是用一个数组去存储字符串的长度呢?虽然说会比较省时,但是我直接用string的size()函数怎么就错了呢!!!这个是AC的代码#include #include using namespace std;int main(){ string s[102]; int index = 0, max... 阅读全文
posted @ 2013-07-11 22:18 Norcy 阅读(580) 评论(0) 推荐(0)
摘要:#include #include using namespace std;int main(){ int a; cin >> a; assert(a>0); //assert,a>0时没问题,a<=0时 程序抛出异常 cout << a << endl; system("pause");} 阅读全文
posted @ 2013-07-10 23:55 Norcy 阅读(217) 评论(0) 推荐(0)
摘要:#include1、sscanf和scanf的不同是输入来源,前者是一个字符串,后者则是标准输入设备2、sscanf的使用,以解析时间字符串为例,将字符串“2009-01-02_11:12:13”解析为整型年月日时分秒//定义char cc;tm tm_temp={0};string stime("2009-01-02_11:12:13");//(1) 必须严格按照分隔符形式匹配填写,若遇到不匹配项则终止解析sscanf(stime.c_str(), "%4d-%2d-%2d_%2d:%2d:%2d",&tm_temp.tm_year, & 阅读全文
posted @ 2013-07-10 23:52 Norcy 阅读(780) 评论(0) 推荐(0)