SRM 609(1-250pt, 1-500pt)
嗯。。。。还是应该坚持写题解的好习惯啊。。。
DIV1 250pt
这难度是回到srm 300+的250了嘛。。。略
// BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "MagicalStringDiv1.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 MagicalStringDiv1
{
public:
int getLongest(string s){
int t1 = , t2 = sz(s)-, num = ;
while (t1 <= t2){
while (t1 < sz(s) && s[t1] != '>') ++ t1;
while (t2 >= && s[t2] != '<') -- t2;
if (t1 <= t2) -- t2, ++ t1, num += ;
}
return num;
} // 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(); }
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 Arg0 = "<"; int Arg1 = ; verify_case(, Arg1, getLongest(Arg0)); }
void test_case_1() { string Arg0 = ">>><<<"; int Arg1 = ; verify_case(, Arg1, getLongest(Arg0)); }
void test_case_2() { string Arg0 = "<<<>>>"; int Arg1 = ; verify_case(, Arg1, getLongest(Arg0)); }
void test_case_3() { string Arg0 = "<<<<><>>><>>><>><>><>>><<<<>><>>>>><<>>>>><><<<<>>"; int Arg1 = ; verify_case(, Arg1, getLongest(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
MagicalStringDiv1 ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
DIV1 500pt
题意:有k种颜色的球,每种颜色有an[i]个(an[i] > 0)。有两种背包,每种背包都有无限多个,第一种背包里面装的所有球颜色必须相同,第二种背包里面装的球颜色不能有相同的。无论哪一种背包,最多都只能装k个。问,最少用多少个背包能装下所有球。
an[i] <= 10^9, k <= 10^5
解法:嗯。。。首先,如果不要求每个背包最多装k个,那就很简单了。直接用an[i]枚举有多少个第二种背包,然后第一种背包的数量就是n - i - 1。
然后,加上每个背包只能装k个的限制条件,就是首先对k个背包预处理一遍,an[i] %= k。后面一步是yy出来的。。。感觉是这样,不知道怎么证。。。
tag:think
// BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "PackingBallsDiv1.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 = / ; int an[];
vi yu; class PackingBallsDiv1
{
public:
int minPacks(int n, int a, int b, int c, int mod){
an[] = a;
for (int i = ; i < n; ++ i) an[i] = ((int64)an[i-] * b + c) % mod + ; int64 num = ;
for (int i = ; i < n; ++ i){
num += an[i] / n;
an[i] %= n;
}
sort (an, an+n); //if (n == 3) for (int i = 0; i < n; ++ i) tst (an[i]);
//cout << endl;
//
int64 cnt = n;
for (int i = ; i < n; ++ i){
int64 tmp = an[i] + n - i - ;
cnt = cnt > tmp ? tmp : cnt;
}
return (int)(cnt + num);
} // 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(); }
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 Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; verify_case(, Arg5, minPacks(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; verify_case(, Arg5, minPacks(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; verify_case(, Arg5, minPacks(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; verify_case(, Arg5, minPacks(Arg0, Arg1, Arg2, Arg3, Arg4)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
//freopen( "a.out" , "w" , stdout );
PackingBallsDiv1 ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
SRM 609(1-250pt, 1-500pt)的更多相关文章
- 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和 ...
- SRM593(1-250pt,500pt)
SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
- topcoder srm 553
div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...
- topcoder srm 552
div1 250pt: 题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个 解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分 ...
- topcoder srm 551
div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...
- topcoder srm 550
div1 250pt: 题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面 ...
- topcoder srm 610
div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...
随机推荐
- ceph入门学习链接
https://tobegit3hub1.gitbooks.io/ceph_from_scratch/content/introduction/component.html
- webbench
Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测 ...
- 《JavaScript高级程序设计》笔记(3):传递参数
待更新... 9.17更新: ECMAScript中所有函数的参数都是按值传递的.也就是说,把函数外部复制给函数内部的参数,就和把值从一个变量复制到另一个变量一样.基本类型值的传递如同基本类型变量的复 ...
- 通过表名显示数据库中该表的表头和内容(mysql扩展库操作)
编写一个函数,接收一个表名,然后把表的表头和内容显示在网页 <?php function readTab($tableName){ $conn=mysql_connect("local ...
- osg学习笔记3 简单几何模型
osg::Geode (geometry node) osg::Geode类表示场景中的渲染几何叶节点,它包含了渲染用的几何信息,没有子节点. 要绘制的几何数据保存在osg::Geode管理的一组os ...
- VC菜菜鸟:建立第一个基于Visual C++的Windows窗口程序
建立第一个基于VisualC++的Windows窗口程序: 发表于:http://blog.csdn.net/it1988888/article/details/10306585 a)执行命令:新建 ...
- Socket实现简单的聊天通信
最近学习了Socket后,感觉Socket挺好玩的,在博客中看到socket在实时聊天功能的很强大,于是乎就做了一个简单的聊天功能,今天贴出来,能够与大家一起共享,有不对之处,能够给予指出,谢谢! 服 ...
- SQL操作(增删改查)
1.一些重要的SQL命令: SELECT - 从数据库中提取数据UPDATE - 更新数据库中的数据DELETE - 从数据库中删除数据INSERT INTO - 向数据库中插入新数据CREATE D ...
- csu 10月 月赛 I 题 The Contest
Description 殷犇有很多队员.他们都认为自己是最强的,于是,一场比赛开始了~ 于是安叔主办了一场比赛,比赛有n个题目,每个题目都有一个价值Pi和相对能力消耗Wi,但是有些题目因为太坑不能同时 ...
- 程序异常捕获库 - CrashRpt
CrashRpt.dll用来在应用程序出现异常crash时,捕获到错误. 并收集出错信息: MiniDump文件.硬件信息.系统信息.出错信息.进程信息.服务信息.驱动信息.启动信息.软件列表.端口信 ...