SRM 212 Div II Level One: YahtzeeScore】的更多相关文章

题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #include <iostream> #include <vector> using namespace std; class YahtzeeScore { public: int maxPoints(vector <int> toss); }; int YahtzeeScore…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3003&rd=5858 比较简单. 代码如下: #include <iostream> #include <vector> #include <cmath> #include <string> using namespace std; #define Rate(win, i) ( (double)(win) / (d…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://community.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm223 这道题目最直接最暴力的算法就是遍历每个位置,然后查看是否满足条件,满足条件的话则立刻停止遍历, 这样算法的时间复杂度为O(N^2).不过还有一个更高效的方法,其时…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟练使用 sstream 流可以大大简化操作,如这个题目,如果不用 sstream 流的话,用 sscanf 函数非常麻烦,因为输入的数据中数字的个数不是一样的,还有一个问题就是多关键字的排序,用 sort 函数时要自己写比较函数. 另外那个得到实现四则运算的方法也很巧妙,我刚始用的方法比较麻烦,这种方法看别人…
题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直接将参数ratings中字符串连接起来就可以, 不用在每个元素后面加空格. 我开 始就以为每个元素连接的时候在后面要加空格分隔, 然后再把重复的元素去掉, 结果system test出错了, 调试半 天不知道什么问题. 而且题目是面也说了, 没有相重复的数据. 由此可见, TopCoder上有些题目看似简单,…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <iostream> #include <string> #include <cmath> using namespace std; class SemiPerfectSquare { public: string check(int N); }; string SemiPerfectS…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> #include <vector> #include <algorithm> using namespace std; int F[50]; class SpaceWarDiv2 { public: int minimalFatigue(vector <int> magica…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 next_permutation 函数的用法. #include <iostream> #include <vector> #include <limits> #include <algorithm> using namespace std; class Col…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> #include <string> using namespace std; string minstr = ""; class SwappingDigits { public: string minNumber(string num); }; string SwappingDi…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个,结果在2s内算不出结果来. 参考了别人算法,学到了set容器的一个用法,用set省去了查找Dijkstra算法中选择最短路径的那一步,set中的第一个元素就是最小值,用priority queue应该也可以. #include <iostream> #include <string>…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, 但写的时候要特别小心,如果直接按照公式算,没有加下面这一句的话: if (total + total * taxPercent / 100 + (tip + 1) * total / 100 <= money) { ++tip; } 那么因为公式涉及向下约分的运算,那么所得到的tip的值可能是比最大值…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12699 这道题目是第一次在比赛的时候做出来的,开始还想用brute force,后来发现那太复杂了,于是在纸上画了画,发现一个规律,那就是只有在一个2x2的cell中,如果出现3个N或3个Z方式的cell,那么这种情况下肯定是无法配色成功,因为最后一定会有两个相邻点为相同的颜色.如果没有这样的情况存在,那么是一定可以配色成功的,根据这点代码就好写了. 代码如下: #i…
题目 考虑DP.\(f(msk,i)\) 表示集合 \(msk(一定包含0号点)\) ,选了恰好i条边的连通方案数.转移用容斥,用这个点集内部所有连边方案减去不连通的.令\(|e_{msk}|\)表示两个端点都在集合msk内的边数,D为\(e_{\complement_{msk}sub}\)(sub在msk中补集内部的边集).转移式:\(f(msk,i)=\binom{|e_{msk}|}{i}-\sum_{sub \in msk,0 \in sub,0 \leq j \leq i} f(sub…
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/Blog-of-Eden/p/8407296.html Topcoder SRM 562 Div 1 - Problem 1000 InducedSubgraphs 当K*2<=N的时候,显而易见的是编号为i(K<=i<=N-K+1)的点一定会形成一条链. 枚举合法的这样的链,剩下的暴力dp吧…
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相加,含有n个不同变量的式子的最大值. 另外限制了每一个变量的最大最小值R[i]和L[i]和所有变量之和的最大值Max. n<=13 题外话: 刚开始做这道题的时候,感觉意外眼熟? codeforces 839 E(此题的退化版):http://codeforces.com/contest/839/pro…
SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, v)有路径的点对数,似乎有不需要构造出原图的方法). 当时我的做法是 直接构造一个网络,跑最大流. 比赛后总觉得这个题有什么神奇的性质,于是搜了一下相关资料: 有一篇关于得分序列的论文:http://www.sciencedirect.com/science/article/pii/0095895…
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN][MAXN]; int main(void) //Codeforces Round #212 (Div. 2)…
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复杂度O(1). 参考程序段 #include <bits/stdc++.h> using namespace std; class PointDistance { public: vector <int> findPoint( int x1, int y1, int x2, int y…
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12610 这道题比较有意思,估计是中国人出的吧,以前都不知道身份证还这么麻烦,不过程序不难写. #include <algorithm> #include <iostream> #include <queue> #include <vector> #include <list> #include <stri…
第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<set> #include<map&…
250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamelCase(string str) { int p = 0; while ((p = str.find('_', p)) != string:: npos) { str[p + 1] = toupper(str[p + 1]); str.erase(p, 1); p = p + 1; } return…
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs.com/lautsie/p/4245242.html BFS和DFS都可以,注意的是,写的时候,可以往que里几个东西一起扔,就不用建立对象了.也可以直接用二维矩阵记录blocked和visited. 剪枝什么的,最基本的是发现其实在步数限制的情况下,棋盘就是有界的了. 第三题:http://ap…
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #include <vector> #include <algorithm> using namespace std; class Target { public: vector <string> draw(int n) { vector<string> result(n,…
题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是否有解,即是否存在n为整数,使得所有分数的和加起来为x+y,即判断n2+n-2(x+y)=0,存在整数解, 根据二次方程的根为(-1±Δ)/2 为整数,其中Δ=√(1+8(x+y)) , 即判断1+8(x+y)是否能开方以及Δ是否为奇数(如果Δ为偶数,则根不是整数) 如果前面条件满足,在通过贪心,从…
题意: 给你一张图,N个点(0~N-1),m条边,国王要从0到N-1,国王携带一个值,当走到一条边权大于此值的边时,要么不走,要么提升该边的边权,提升k个单位花费k^2块钱,国王就带了B块钱,问能携带的最大值是多少. 解法:  二分此值,然后BFS跑遍每个点,记录到达每个点的最小花费Mincost,如果Mincost[N-1] <= B,则此值可行,往上再二分,否则往下二分. 比赛时候本来我的二分方法应该返回high的,结果返回low,怎么都过不了样例,比赛完才发现此处的问题.  真是太弱. 代…
题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数. 解法: 这题是我傻逼了,处理上各种不优越,要使n*(n+1)/2 >= 10^12, n为10^6是不够的,要开大一点,总是细节地方不注意. 做法很简单,先用map或者其他什么东西判断x+y是否为某个n*(n+1)/2, 如果不是,那肯定为-1,再就是x=0有可能要单独考虑,然后就是选一些数凑成x,由于要最少,那么从大的开始凑起,可以暴力地凑,也可以…
body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } Problem Statement      You have an array with N elements. Initially, each element is 0. You can perform the following operations: Increment operation:…
D. Fools and Foolproof Roads   You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs…
题意:给一个点(x,y),给一些步长delta1,delta2...deltaN,问从(0,0)严格按照步长走完N步后能否正好到达(x,y)点. 解法:其实就是判断这些线段和(0,0)-(x,y)这条线段能否构成一个多边(角?)形的问题,只需判断最长的边是否不大于于所有边长和的一半即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #inclu…
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还A了.. dp[i][j]表示前i个堆里选j个人,每一个堆都有o[i]个人,枚举堆里,可以选多少个人. 第二题,写了将近半个小时...没太想好,到底是求最长路还是求最短路,边调边想,浪费些时间. 第三题,发现最近做组合问题,不是那么搓了... rating涨了131,进div1!! 1000的关键代…