TCO14 2B L3: AlwaysDefined,math,从余数入手
来源:互联网 发布:java api介绍的书籍 编辑:程序博客网 时间:2024/05/16 06:27
题目:http://community.topcoder.com/stat?c=problem_statement&pm=13060&rd=15996
参考:http://apps.topcoder.com/wiki/display/tc/TCO+2014+Round+2B
将数按对W的余数进行分类。做题思维要非常清晰,难度不小,看题解看了半天才看懂。
代码:
#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <iostream>#include <sstream>#include <iomanip>#include <bitset>#include <string>#include <vector>#include <stack>#include <deque>#include <queue>#include <set>#include <map>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <cstring>#include <ctime>#include <climits>using namespace std;#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)typedef pair<int, int> pii;typedef long long llong;typedef pair<llong, llong> pll;#define mkp make_pair/*************** Program Begin **********************/vector<vector<int>> g;class AlwaysDefined {public:inline long long items(long long rem, long long upper, int W){// rem + (cnt - 1) * W < upperlong long numbers = upper - rem;return (numbers + W - 1) / W;}long long solve(int W, int rem, long long cnt){if (cnt <= 0) {return 0;}if (1 == rem) {return cnt;}long long ans = 0;for (int i = 0; i < g[rem].size(); i++) {int x = g[rem][i];long long smallest = rem + x * W;long long newrem = smallest / rem;ans += solve(W, newrem, items(x, cnt, rem));// rem 为一个周期}return ans;}long long countIntegers(long long L, long long R, int W) {long long res = 0;g.resize(W);for (int i = 0; i < g.size(); i++) {g[i].clear();}for (int rem = 1; rem < W; rem++) {for (int x = 0; x < rem; x++) {if ( (x * W) % rem == 0 ) {g[rem].push_back(x);}}}for (int rem = 1; rem < W; rem++) {res += solve(W, rem, items(rem, R + 1, W));res -= solve(W, rem, items(rem, L, W));}return res;}};/************** Program End ************************/
0 0
- TCO14 2B L3: AlwaysDefined,math,从余数入手
- TCO14 2B L2: SumAndProductPuzzle, math, 推理
- TCO14 1C L3: RedPaint,dp,math
- TCO14 1B L3: EagleInZoo, dp,tree
- TCO14 1B L2: WolvesAndSheep, brute force
- [矩阵树定理 拉格朗日插值] TCO14 Round 3B TreeDistance
- TCO14 2A L1: SixteenBricks, Greedy
- [随便搞搞] TCO14 Round 2C InverseRMQ
- 3B入手
- SRM 596 D2 L3:SparseFactorialDiv2,math
- java从哪里入手!
- 从JavaCC入手
- 第一章 从何处入手
- 从LFS入手
- 农村包围城市,从边缘入手
- POJ NOI MATH-7647 余数相同问题
- ADS-B SBS-3入手
- TCO14 2C L2: CliqueGraph,graph theory, clique
- Jump Game II
- 152 - Tree's a Crowd
- date类型网页与数据库的转换 工具类
- ifconfig命令
- cglib导致permSize Space
- TCO14 2B L3: AlwaysDefined,math,从余数入手
- The New Start
- 黑马程序员,黑马论坛----Java+云计算4期,100%全部就业,平均薪水6965元!
- 黑马程序员——高新技术.反射
- 题海无涯2
- 分页类
- UVa 11494 - Queen
- 黑马程序员,黑马论坛----黑马.Net 10期 史无前例的就业速度12天就业71.43%
- hdu 4888 最大流给出行列和求矩阵