2014年2月21日
摘要: 原题链接注意任何数的0次方都为1.#include int main(){ int a, b; while(scanf("%d%d", &a, &b) == 2){ if(b == 0){ printf("1\n"); continue; } b = (b - 1) % 4 + 1; int t = a = a % 10; for(int i = 1; i < b; ++i) a *= t; printf("%d\n", a % 10); } return 0;} 阅读全文
posted @ 2014-02-21 23:06 长木Qiu 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include int main(){ int n, a, b, t; while(scanf("%d", &n) == 1){ a = b = 0; while(n-- && scanf("%d", &t)) if(t & 1) ++b; else ++a; printf("%d\n", b & 1 ? b : a); } return 0;} 阅读全文
posted @ 2014-02-21 16:14 长木Qiu 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题坑了不少人,要考虑n为负的情况。好在不管它是正是负总归是等差数列吧,这样规律就明显了,直接用(首项 + 末项)* 项数 / 2;由于n的范围在10000之内,所以不需要考虑溢出的情况。关键是项数 = 首尾差的绝对值 + 1;#include #include int main(){ int n; while(scanf("%d", &n) == 1) printf("%d\n", (abs(n - 1) + 1) * (1 + n) / 2); return 0;} 阅读全文
posted @ 2014-02-21 00:17 长木Qiu 阅读(122) 评论(0) 推荐(0) 编辑