SRM 387(1-250pt)
DIV1 300pt
题意:有m种颜色的球若干个放在n个盒子里。每次操作可从一个盒子里拿出任意个球(不必同色),放进另一个盒子。要求终态为:1、最多有一个盒子里面装有不同色的球,该盒子成为joker box,也可以没有joker box;2、除了joker box,其他盒子要么为空,要么都为同色球;3、对于每种颜色的球,除了在joker box里的球,其余都在同一个盒子里,或者该颜色所有球都在joker box。
给定初态时n个盒子里含有每种颜色的球各多少个,问转移到终态最少需要操作多少次。
解法:贪心。有一种操作是,首先选出一个joker box,然后将其他盒子里的所有球全部拿到joker box里面,这样操作次数为n-1,每个盒子操作一次。而对于任意一个盒子,要使操作次数为0,有两种可能:1、初态时它为空;2、初态时它仅含一种颜色t的球,且之前没有盒子初态仅含颜色t的球。如果不满足则两个条件,直接将盒子拿空。
tag:greedy, good
// BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "MarblesRegroupingEasy.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; class MarblesRegroupingEasy
{
public:
bool vis[];
int minMoves(vector <string> v){
clr0 (vis);
int cnt = ;
for (int i = ; i < sz(v); ++ i){
string s = v[i];
int tmp = , idx = ;
for (int j = ; j < sz(s); ++ j)
if (s[j] != '') ++ tmp, idx = j;
if (!tmp) continue;
if (tmp == && !vis[idx]){
vis[idx] = ; continue;
}
++ cnt;
}
if (cnt) -- cnt;
return cnt;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { string Arr0[] = {"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
void test_case_1() { string Arr0[] = {"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
void test_case_2() { string Arr0[] = {"",
"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
void test_case_3() { string Arr0[] = {"",
"",
"",
"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
void test_case_4() { string Arr0[] = {"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
MarblesRegroupingEasy ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
SRM 387(1-250pt)的更多相关文章
- SRM593(1-250pt,500pt)
SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
- SRM468 - SRM469(1-250pt, 500pt)
SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
- SRM 609(1-250pt, 1-500pt)
嗯....还是应该坚持写题解的好习惯啊... DIV1 250pt 这难度是回到srm 300+的250了嘛...略 // BEGIN CUT HERE /* * Author: plum rain ...
- SRM 442(1-250pt, 1-500pt)
DIV1 250pt 题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime.比如12 = 2*2*3,则含3个数字,是underprime.求A, B之间un ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
随机推荐
- hibernate 连接 oracle数据库
前言:以下所有的操作都是基于你已经成功安装了oracle数据库并且java的开发环境正常的情况下进行的. 如果没有完善请先配置基础环境. 第一步:配置需要的环境(下载并导入需要的包). 我的百度云盘里 ...
- c#yield,IEnumerable,IEnumerator
foreach 在编译成IL后,实际代码如下: 即:foreach实际上是先调用可枚举对象的GetEnumerator方法,得到一个Enumerator对象,然后对Enumerator进行while循 ...
- MVC权限模块
设计方向: 1.摒弃SiteMap,避免在容易书写错误的sitemap中书写,导航在controller和action上打标签生成. 2.controller统一继承basecontroller,在b ...
- Function.prototype.apply()
文章地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply ...
- js 通过function来定义函数
什么是函数: 函数是完成某一功能的代码段. 函数是可重复执行的代码段. 函数方便管理和维护. 自定义一个函数: 通过function关键字来定义一个函数. 语法: function 函数名称([可 ...
- js获取星期几
function getweek(time) { /*显示星期*/ /*time为date格式*/ var str; var d = time.getDay(); switch (d) { case ...
- StrongReference
原创作品:未经本人允许,不得转载前段时间写项目时遇到了一个问题,就是从网络获取图片资源的问题,总是出现OOM异常,经过几天的努力,终于处理的还算是可以使用,OOM的处理一直都是很头疼的问题.对于三级缓 ...
- Ext.String 方法
1.Ext.String.htmlEncode(value); 编码字符串,对其中特殊字符进行转义 xt.String.htmlEncode("hello'world"); //& ...
- mac+eclipse+svn+maven经验总结(转)
1.Eclipse for Mac:http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/indigo/SR2/ecl ...
- 写了几天的博客-feel
写博客 真的总结我自己的知识.长见识了.记录下自己遇到的东西,算是一个总结,有问题了,还可以回头看一下.很好 真的很好.