DIV1 250pt

题意:有几家宠物店,vecort<int>A表示每家宠物店含有小狗占小狗总数的百分比。现在要做扇形统计图统计每家店的小狗百分比,如下图,问作出来的扇形统计图中最多含有多少对半径夹角为180度。(左图两对,右图一对) (A.size() <= 8)

解法:因为A.size() <= 8,所以直接暴力枚举A中元素的全排列就好了。我的代码又写复杂了。。。一是枚举全排列可以用next_permutation()函数,另一个是对每个排列统计数量的时候写复杂了,不需要算j < i的情况,只要不除以2就行了。

tag:brute-force

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "SymmetricPie.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 n, ans;
VI an, dn;
bool mp[];
int sum[]; void dfs(int x)
{
if (x == n){
clr0 (sum); sum[] = dn[an[]];
for (int i = ; i < n; ++ i)
sum[i] = sum[i-] + dn[an[i]]; int cnt = ;
for (int i = ; i < n; ++ i)
for (int j = ; j < n; ++ j){
int tmp = j > i ? sum[j] - sum[i] : sum[n-] - sum[i] + sum[j];
if (tmp == ) ++ cnt;
}
ans = max(ans, cnt/);
return ;
} for (int i = ; i < n; ++ i) if (!mp[i]){
an.pb (i); mp[i] = ;
dfs (x + );
an.pop_back(); mp[i] = ;
}
} class SymmetricPie
{
public:
int getLines(vector <int> D){
dn = D;
ans = ; n = sz(dn);
clr0 (mp); an.clear();
dfs ();
return ans;
} // 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 Arg1 = ; verify_case(, Arg1, getLines(Arg0)); }
void test_case_1() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getLines(Arg0)); }
void test_case_2() { int Arr0[] = {,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getLines(Arg0)); }
void test_case_3() { int Arr0[] = {,,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getLines(Arg0)); }
void test_case_4() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getLines(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
SymmetricPie ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV1 500pt

题意:有一张纸,纸上有n * m格,每个格子上有一个数字。若将纸折叠(可以不对折,但是折痕只能在格与格之间,不能穿过格子。),折叠后重合的两个格子原先的值之和即为现在的值,比如1*2的纸含有两个数字1,2,折叠后含有一个数字3。折叠完成后,最终纸上所有数字中最大的为max。问随意折叠多少次,求max最大为多少。n <= 12,m <= 12,-100 <= A[i][j] <= 100

解法:也是暴力,只不过要预处理+暴力。只是开始我想到暴力的时候觉得这样不好写,而且感觉好慢可能不行,就没有细想了。。。所以也没有做出来。暴力的方法是,先预处理哪些列最终可能折叠在一起,再预处理哪些行最终可能会折叠在一起,然后对于处理出来的东西枚举就好了。我看了官方题解也没想好怎么写,然后又看了它推荐的代码才弄懂。

tag:brute-force

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "FoldThePaper.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 n, m;
int an[][];
bool can[<<];
vector<vi> row, col; vi getvec(int x, int f)
{
vi v;
for (int i = ; i < (f ? m : n); ++ i)
if (x & (<<i)) v.pb (i);
return v;
} void rec(vi v){
//for (int i = 0; i < sz(v); ++ i)
//tst (v[i]);
//cout << endl;
int n = sz(v);
for (int i = ; i < n; ++ i)
can[v[i]] = ;
for (int i = ; i < n; ++ i){
vi nv(max(i, n-i));
if (i <= n/){
for (int j = i; j < n; ++ j)
nv[j-i] = v[j];
for (int j = , k = i-; j < i; ++ j, -- k)
nv[j] |= v[k];
}
else{
for (int j = ; j < i; ++ j)
nv[j] = v[j];
for (int j = i, k = i-; j < n; ++ j, -- k)
nv[k] |= v[j];
}
rec(nv);
}
} class FoldThePaper
{
public:
int getValue(vector <string> pap){
n = sz(pap);
stringstream stm;
for (int i = ; i < n; ++ i){
stm << pap[i]; m = ;
while (stm >> an[i][m]) ++ m;
stm.clear();
}
clr0 (can);
vi v;
for (int i = ; i < n; ++ i) v.pb (<<i);
rec(v);
row.clear();
for (int i = ; i < (<<n); ++ i) if (can[i])
row.pb (getvec(i, )); v.clear(); clr0 (can);
for (int i = ; i < m; ++ i) v.pb (<<i);
rec(v);
col.clear();
for (int i = ; i < (<<m); ++ i) if (can[i])
col.pb (getvec(i, )); int ans = -inf;
for (int i = ; i < sz(row); ++ i)
for (int j = ; j < sz(col); ++ j){
int tmp = -inf;
for (int t = ; t < sz(row[i]); ++ t)
for (int k = ; k < sz(col[j]); ++ k){
if (tmp == -inf) tmp = an[row[i][t]][col[j][k]];
else tmp += an[row[i][t]][col[j][k]];
}
ans = max(tmp, ans);
}
return ans;
} // 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[] = {
"1 1 1",
"1 1 1"
}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getValue(Arg0)); }
void test_case_1() { string Arr0[] = {
"1 -1",
"1 -1"
}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getValue(Arg0)); }
void test_case_2() { string Arr0[] = {
"1 -1 -1 1",
"-1 -1 -1 -1",
"-1 -1 -1 -1",
"1 -1 -1 1"
}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getValue(Arg0)); }
void test_case_3() { string Arr0[] = {
"20 13 -2 100",
"-12 0 4 -3",
"4 1 -36 21"
}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getValue(Arg0)); }
void test_case_4() { string Arr0[] = {
""
}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, getValue(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
FoldThePaper ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 406(1-250pt, 1-500pt)的更多相关文章

  1. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  2. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  3. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  4. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  5. topcoder srm 553

    div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...

  6. topcoder srm 552

    div1 250pt: 题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个 解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分 ...

  7. topcoder srm 551

    div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...

  8. topcoder srm 550

    div1 250pt: 题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面 ...

  9. topcoder srm 610

    div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...

随机推荐

  1. oracle模糊查询效率可这样提高

    1.使用两边加'%'号的查询,oracle是不通过索引的,所以查询效率很低. 例如:select count(*) from lui_user_base t where t.user_name lik ...

  2. For Me ...

    一直有做博客的打算,但是这也看不上,那也看不上. 总想着做一个personal blog,界面,风格全由自己设计. 可时间上总是不充裕的. 可技术上总是欠火候的. 可内容上总是待斟酌的. 于是时间被我 ...

  3. php利用smtp类轻松的发送电子邮件

    当你还在纠结php内置的mail()函数不能发送邮件时,那么你现在很幸运,此时的这篇文章可以帮助到你! php利用smtp类来发邮件真是屡试不爽,我用过很久了,基本上没出过问题.本博客后台,当博主回复 ...

  4. JS & JQuery 动态添加 select option

    因为是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接有时候会失效,所以 ...

  5. 【POJ2155】【二维树状数组】Matrix

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  6. Python中%s和%r的区别

    早先使用Python工作的时候,对于格式化输出%s和%r的使用都是混着用的. 这一次就出错了: cu.execute("insert into ipPool values(null, '%r ...

  7. 原生js实现回到顶部

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...

  8. ZOJ 3872 Beauty of Array

    /** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...

  9. Unity3D动态加载外部资源

    最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质上我理解没有什么区别.Resources ...

  10. TCP协议握手与分手

    TCP(Transmission Control Protocol) 传输控制协议 TCP的7次握手可以理解为3次握手和4次分手. TCP状态转换图,如下: 这个图N多人都知道,它对排除和定位网络或系 ...