2014年2月12日
摘要: 原题链接设金片数量为n时所需要的步骤为F(n),则易得递推式F(n) = 2F(n-1) + 1; 易推得F(n) = 2^n - 1;但是一般的累乘容易超时,这题需要一个时间消耗为O(log n)的算法。附ac代码:#include #define mod 1000000long long power(int n){ //若n为偶数,则n个2相乘,等于前n/2个2相乘的平方 //若n为奇数,则n个2相乘,等于前n/2个2相乘的平方再乘以2 if(n == 1) return 2; long long t = power(n / 2) % mod; t = t * t % mod; if(n 阅读全文
posted @ 2014-02-12 12:45 长木Qiu 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 原题链接由于10可以分解为质因数2 * 5,所以可以将原阶乘分解求出2和5因子的数量,则末尾0的个数就是2和5中数量较少的那个的数量。附ac代码:#include int main(){ int t, n; scanf("%d", &t); while(t-- && scanf("%d", &n)){ int a = 0, b = 0; //分别存储质因子‘2’和、‘5’的数量 int x = n; //副本 while(x) a += (x /= 2); while(n) b += (n /= 5); printf(&q 阅读全文
posted @ 2014-02-12 10:50 长木Qiu 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 原题链接直接应用递推公式打表。附ac代码:#include int main(){ int t, n, a[41] = {0, 0, 1, 2}; for(int i = 4; i != 41; ++i) a[i] = a[i - 1] + a[i - 2]; scanf("%d", &t); while(t-- && scanf("%d", &n)) printf("%d\n", a[n]); return 0;} 阅读全文
posted @ 2014-02-12 01:23 长木Qiu 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题不需要考虑+123 +456的情况,所以就简单了一些。附ac代码:#include #include #define MAX 1000 + 1char a[MAX], b[MAX];int main(){ int x, y; while(scanf("%s%s", a, b) == 2){ if(a[0] == b[0] && a[0] == '0') break; x = strlen(a); y = strlen(b); if(a[0] != '-' && b[0] != '-' 阅读全文
posted @ 2014-02-12 01:08 长木Qiu 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题,只要将乘客体重排序就好办了。附ac代码:#include #include int a[301];int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int t, w, n, x, count; scanf("%d", &t); while(t-- && scanf("%d%d", &w, &n)){ x = n; while(x--) scanf("%d", & 阅读全文
posted @ 2014-02-12 00:38 长木Qiu 阅读(110) 评论(0) 推荐(0) 编辑
  2014年2月11日
摘要: 原题链接这题需要一些小技巧。附ac代码:#include int main(){ int t, n, m, count, x; scanf("%d", &t); while(t-- && scanf("%d%d", &n, &m)){ count = 0; n -= n % m; while(n >= m){ x = n; while(x % m == 0){ ++count; x /= m; } n -= m; } printf("%d\n", count); } return 0;}再 阅读全文
posted @ 2014-02-11 23:54 长木Qiu 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 原题链接直接用log10函数。注意结果要保存到double中。附ac代码: #include #include int main(){ int n, t; double count; scanf("%d", &t); while(t-- && scanf("%d", &n)){ count = 1; while(n) count += log10(n--); printf("%d\n", (int)count); } return 0;} 再附上NYOJ上的标程:(感谢原作者feihu) /* NYOJ 阅读全文
posted @ 2014-02-11 22:19 长木Qiu 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 原题链接考察数学知识(百度了好久才找到这个数学知识点):在平面上作向量AB、ACAB叉乘AC为正,则是逆时针,为负为顺时针.记向量AB为(dx1, dy1) = (x2-x1, y2-y1)向量AC为(dx2, dy2) = (x3-x1, y3-y1)叉积为|dx1 dy1||dx2 dy2|即:dx1 * dy2 - dy1 * dx2附ac代码:#include int main(){ int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, t; while(scanf("%d%d%d%d%d%d", &x1, &y1, 阅读全文
posted @ 2014-02-11 21:45 长木Qiu 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 原题链接已知三角形PMN三个顶点坐标为(x1, y1) (x2, y2) (x3, y3),求该三角形的面积SS = |(x1y2+y1x3+x2y3-x1y3-y1x2-y2x3)| / 2知道这个公式就好办了。附ac代码:#include #include int main(){ int x1, y1, x2, y2, x3, y3; while(scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3), x1 || y1 || x2 || y2 || x3 || y3) pr 阅读全文
posted @ 2014-02-11 17:55 长木Qiu 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 原题链接关键点是通分后判断分子分母能否整除附ac代码:#include int main(){ int t, k, x, y, tempa, tempb; scanf("%d", &t); while(t-- && scanf("%d", &k)){ for(y = k + 1; y = y) printf("1/%d=1/%d+1/%d\n", k, x, y); } } } return 0;} 阅读全文
posted @ 2014-02-11 17:24 长木Qiu 阅读(142) 评论(0) 推荐(0) 编辑