SRM387 div1
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的更多相关文章
- CF#345 (Div1)
论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...
- 图论 SRM 674 Div1 VampireTree 250
Problem Statement You are a genealogist specializing in family trees of vampires. Vampire famil ...
- jq对象转为dom对象:$(".div1")[0] dom对象转为jq对象:$(dom对象)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 第一次div1做出3道题
第一次div1做出3道题! 再接再厉! 哈利路亚!
- 第一次进div1了
第一次进div1~好激动啊! 上帝依旧那么眷顾我!
- TopCoder 649 div1 & div2
最近一场TC,做得是在是烂,不过最后challenge阶段用一个随机数据cha了一个明显错误的代码,最后免于暴跌rating,还涨了一点.TC题目质量还是很高的,非常锻炼思维,拓展做题的视野,老老实实 ...
- 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 ...
- codeforces #305 div1 done
总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
随机推荐
- N! (大数,优化)
Problem Description 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入 ...
- 图片延时加载原理 和 使用jquery实现的一个图片延迟加载插件(含图片延迟加载原理)
图片加载技术分为:图片预加载和图片延时加载. javascript图片预加载和延时加载的区别主要体现在图片传输到客户端的时机上,都是为了提升用户体验的,延时加载又叫懒加载.两种技术的本质:两者的行为是 ...
- BZOJ 1977[BeiJing2010组队]次小生成树 Tree - 生成树
描述: 就是求一个次小生成树的边权和 传送门 题解 我们先构造一个最小生成树, 把树上的边记录下来. 然后再枚举每条非树边(u, v, val),在树上找出u 到v 路径上的最小边$g_0$ 和 严格 ...
- python基础之Day4
流程判断 一.if 1.语法一 各条件都执行 if条件1: if条件2: if条件3: 2.语法二 if多分支,自上而下执行,一旦满足条件,后面代码即使满足条件也不会执行 if条件1: elif条件2 ...
- libpcap 库使用(一)
参考资料: http://www.tcpdump.org/ DESCRIPTION The Packet Capture library provides a high level interface ...
- MySQL 检索数据及提高检索速度的方法
检索数据 mysql> SELECT [DISTINCT] 表名.列名,表名.列名,表名.列名 -- 使用通配符*表示所有列 DISTINCT表示返回不同的值 -> FROM 数据库名.表 ...
- [Hbase]Hbase技术方案
HBase架构简介 HBase在完全分布式环境下,由Master进程负责管理RegionServers集群的负载均衡以及资源分配,ZooKeeper负责集群元数据的维护并且监控集群的状态以防止单点故障 ...
- 一台老服务器的升级日志(PHP4.4.9+MySQL5.1)升级MySQL5.6
1.备份数据库 mysqldump -uroot -p --all-databases > databases.sql 2.停止mysql服务 service mysqld stop 3.卸载旧 ...
- Windows 平台 (UWP)应用设计
Make Your Apps Cooperate with Cross-App Communication : https://rewards.msdn.microsoft.com/Challeng ...
- win8 本地化
先看个简单的案例:新时尚Windows8开发(6):资源 & 本地化 http://www.silverlightchina.net/html/windows8/study/2012/0902 ...