250pt:

题目:有一些盒子(不大于50个),每个盒子里有一些大理石(最多50种颜色),然后给定每个盒子里每种颜色大理石的个数(没有为0),求最少操作几步满足:

1:最多只能一个盒子里有多种颜色,叫做jaker

2:每种颜色最多位于一个一个非jaker的盒子里,且每个非jaker的盒子最多只含有一种颜色:

移动一步可以移动一个盒子任意个石头到另外一个。。

思路:如果我们枚举哪个是jaker,那么对于剩下来的盒子,就剩下要不要移动到jaker里的抉择了。。而且:

1: 如果该盒子有多种颜色,那么一定要移动,全部移动到jaker里就行

2: 如果该盒子有只有一种颜色,那么该颜色用过(就是在前面也有一个只有该颜色的)则必须移动,否者不移动

3:空盒子不移动

code:

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "MarblesRegroupingEasy.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#define M0(a) memset(a, 0, sizeof(a))
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; int vis[], n, m;
vector<string> a;
int work(int nt){
M0(vis);
int ret = ;
for (int i = ; i < n; ++i)
if (i != nt){
int cnt = , p = -;
for (int j = ; j < m; ++j)
if (a[i][j] != '') ++cnt, p = j;
if (cnt == ) continue;
else if (cnt > ) ret ++;
else {
if (!vis[p]) vis[p] = ;
else ++ret;
}
}
return ret;
} class MarblesRegroupingEasy
{
public:
int minMoves(vector <string> b)
{
n = b.size();
m = b[].size();
a = b;
int ret = ;
for (int i = ; i < n; ++i)
ret = min(ret, work(i));
return ret;
} // 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()
{
MarblesRegroupingEasy ___test;
___test.run_test(-);
// system("pause");
return ;
}
// END CUT HERE

500pt:

题目:给定一些一维坐标里的线段,问把他们可以分成多少个子集,每个,子集符合下面情况:

1:任意一个不再子集里的线段与子集相交

2.子集元素都不相交

思路:

因为坐标最大才100,所以以坐标进行统计(类似dp思想)

   直接看代码吗,

不然不好说清楚,代码还是很短的。。

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "IntervalSubsets.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair
#define M0(a) memset(a, 0, sizeof(a))
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int f[]; class IntervalSubsets
{
public:
int numberOfSubsets(vector <int> start, vector <int> finish)
{
int n = start.size();
M0(f);
f[] = ;
for (int i = ; i <= ; ++i){
int L = -;
for (int j = ; j < n; ++j)
if (finish[j] <= i) L = max(start[j], L);
if (L == -)
f[i] = f[i - ];
else
for (int j = ; j < n; ++j)
if (finish[j] >= L && finish[j] <= i) f[i] += f[start[j] - ];
}
return f[];
} // 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() { int Arr0[] = {,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
void test_case_1() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
void test_case_2() { int Arr0[] = {,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
void test_case_3() { int Arr0[] = {,,,,,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,,,,,,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
void test_case_4() { int Arr0[] = {, , , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {, , , }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
IntervalSubsets ___test;
___test.run_test(-);
// system("pause");
return ;
}
// END CUT HERE

SRM387 div1的更多相关文章

  1. CF#345 (Div1)

    论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...

  2. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  3. jq对象转为dom对象:$(".div1")[0] dom对象转为jq对象:$(dom对象)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. 第一次div1做出3道题

    第一次div1做出3道题! 再接再厉! 哈利路亚!

  5. 第一次进div1了

    第一次进div1~好激动啊! 上帝依旧那么眷顾我!

  6. TopCoder 649 div1 & div2

    最近一场TC,做得是在是烂,不过最后challenge阶段用一个随机数据cha了一个明显错误的代码,最后免于暴跌rating,还涨了一点.TC题目质量还是很高的,非常锻炼思维,拓展做题的视野,老老实实 ...

  7. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

  8. codeforces #305 div1 done

    总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...

  9. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

随机推荐

  1. node.js 进程崩溃处理

    process.on('uncaughtException', (err) => { console.error('有错误'); });

  2. java 银联接口开发

    http://blog.sina.com.cn/s/blog_6c868c470100ys59.html 在线接口文档:http://wenku.baidu.com/link?url=EUgAuOKz ...

  3. Java虚拟机的相关笔记

    1.垃圾GC回收事件Minor GC(只清除新生代),Full GC(清除新生代和老年代),Major GC(清除新生.老年代和持久代). 2.堆分为新生代.老年代和持久代,持久代一般存放静态文件. ...

  4. maven clean package 时出现Failed to read artifact descriptor for的问题解决

    maven clean package 时出现Failed to read artifact descriptor for的问题 [ERROR] Failed to execute goal on p ...

  5. linux的!的用法

    !的用法:1.!!:代表上一条命令,如下: 示例一: ./some-shell-command cat !! (相当于cat ./some-shell-command) 示例二: cd /user ! ...

  6. Grunt教程——安装Grunt

    Grunt教程--安装Grunt 作者:大漠 日期:2013-11-04 点击:3124 tools grunt 在上一节<Grunt教程--初涉Grunt>一文中介绍了Grunt是什么, ...

  7. SparkStreaming 监控文件目录

    SparkStream 监控文件目录时,只能监控文件内是否添加新的文件,如果文件名没有改变只是文件内容改变,那么不会检测出有文件进行了添加. )) )).reduceByKey(_ + _) word ...

  8. springMVC学习三 注解开发环境搭建

    第一步:导入jar包 第二步:配置DispatcherServlet  前端控制器 因为此处把DsipatcherServlet的映射路径配置成了"/",代表除了.jsp文件之外, ...

  9. Alpha 冲刺 (4/10)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助前后端接口的开发 测试项目运行的服务器环 ...

  10. python的数字图像处理学习(1)

    导入原有的测试图片,测试图片路径,和一些方法,显示出测试图像,测试图像路径. from skimage import io,data,data_dir img_rgb=data.chelsea() i ...