UESTC第二届ACM趣味程序设计竞赛第三场
2010-12-25 22:15
477 查看
A. Painting
水题,容斥原理,小心又可能有0高度的。
B. WarCraft III
暴力C(24,5)。
C. Apple
有意思的题,问说n个数中有多少种方法,使得连续的数的和与0模m同余。
将前缀和按模m等价类划分。
代码
水题,容斥原理,小心又可能有0高度的。
B. WarCraft III
暴力C(24,5)。
C. Apple
有意思的题,问说n个数中有多少种方法,使得连续的数的和与0模m同余。
将前缀和按模m等价类划分。
代码
#include <iostream> #include <string> #include <stdio.h> #include <string.h> #include <map> #include <algorithm> #include <vector> using namespace std; typedef long long int64; const int MAX = 1000005; int n, k; int64 c[MAX]; int q[MAX]; int lowbit(int t) { return t & (-t); } void insert(int i) { while(i <= n){ c[i]++; i += lowbit(i); } } int64 query(int i) { int64 res = 0; while(i > 0) { res += c[i]; i -= lowbit(i); } return res; } int main() { int T, cc = 0; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &k); int h = 0, t = 0; for(int i = n; i >= 1; i--) { q[t] = i; t = (t + 1) % MAX; for(int j = 0; j < k; j++) { q[t] = q[h]; h = (h + 1) % MAX; t = (t + 1) % MAX; } } int64 ans = 0; memset(c, 0, sizeof(c)); while(h != t) { ans += query(q[h]); insert(q[h]); h = (h + 1) % MAX; } printf("Case #%d: %lld\n", ++cc, ans); } }
相关文章推荐
- UESTC第二届ACM趣味程序设计竞赛第四场
- 2016 UESTC 第八届ACM趣味程序设计竞赛第三场(正式赛)(比赛场)B - 保护果实
- UESTC第七届ACM趣味程序设计竞赛第四场(正式赛)
- UESTC-第五届ACM趣味程序设计竞赛第四场(正式赛)--不完全解题报告
- UESTC 第七届ACM趣味程序设计竞赛第四场(正式赛)
- UESTC 第五届ACM趣味程序设计竞赛第一场(热身赛,非原创题) 解题报告
- uestc 第五届ACM趣味程序设计竞赛第二场(正式赛)棋盘
- 第八届ACM趣味程序设计竞赛第三场(正式赛)官方题解
- UESTC 第五届ACM趣味程序设计竞赛第四场(正式赛) 解题报告
- UESTC-第五届ACM趣味程序设计竞赛第四场(正式赛)--不完全解题报告
- CDOJ 第七届ACM趣味程序设计竞赛第三场(正式赛) 题解
- SDUT 2163 Identifiers 山东省第二届ACM大学生程序设计竞赛
- 山东省第二届ACM大学生程序设计竞赛 Crack Mathmen 打表 模拟
- SDUT 2164 Binomial Coeffcients 山东省第二届ACM大学生程序设计竞赛
- 山东省第二届ACM大学生程序设计竞赛:The Android University ACM Team Selection Contest
- SDUT 2165 Crack Mathmen(快速幂)山东省第二届ACM大学生程序设计竞赛
- 第九届ACM趣味程序设计竞赛第二场(正式赛) B - 绿帽自动机【思维】
- 组队周赛_山东省第二届ACM大学生程序设计竞赛
- 电子科技大学第八届ACM趣味程序设计竞赛第四场(正式赛)题解
- 山东省第二届ACM大学生程序设计竞赛——Mathman Bank