Topcoder SRM584 DIV 2 500】的更多相关文章

#include <set> #include <iostream> #include <string> #include <vector> using namespace std; class Egalitarianism { public: void DFS(vector<string> &v,int p,char flag[]) { int i,j; ;i<v.size();i++) { if (v[p][i]=='Y') {…
题意: 一个游戏有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轮,有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,由于要最少,那么从大的开始凑起,可以暴力地凑,也可以…
题意:给一个点(x,y),给一些步长delta1,delta2...deltaN,问从(0,0)严格按照步长走完N步后能否正好到达(x,y)点. 解法:其实就是判断这些线段和(0,0)-(x,y)这条线段能否构成一个多边(角?)形的问题,只需判断最长的边是否不大于于所有边长和的一半即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #inclu…
Problem Statement      You might have played the game called Memoria. In this game, there is a board consisting of N rows containing M cells each. Each of the cells has a symbol on its back. Each symbol occurs on exactly two cells on the board. A mov…
周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are numbered from 0 to N-1. Some pairs of rooms are connected by bidirectional passages. The passages have the topology of a tree. That is, there are exactly N-…
Problem Statement      Manao is playing a new game called Reflections. The goal of the game is transferring an artifact in 3-dimensional space from point (0, 0, 0) to point (X, Y, Z). There are two types of moves in the game: 1) The player can move t…
#include <string> #include <iostream> using namespace std; class SwappingDigits { public: bool notBiggest(string &s,int pos) { int len=s.length(); ; ;i<len;i++) { )) { return true; } } return false; } int findSmallest(string&s,int p…
这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对..耻辱. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define ll long long using namespace std; #define NN 370000 class Choo…
A:应该是道语文题,注意边界就好: B:开始考虑的太复杂,没能够完全提取题目的思维. 但还是A了!我愚蠢的做法:二分答案加暴力枚举, 枚举的时候是完全模拟的,比如每次取得时候都是从大到小的去取,最后统计答案! 好吧!忽略这种SB做法,只是提供一种当你想不到的时候,一种暴力破解的思路! 看到的一种正解:我们每次可以取(N-1)个,而且不用加入答案中, 先上代码: for (int i=0;i<s.size();i++) sum+=s[i]; return max(0,sum-N*(m-1));很简…