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
上一篇:SSH免密码登录设置


下一篇:JAVA开发人员画图表总结(ECHARTS)