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. SlidingMenu侧换菜单的导入

    对于Adt-22.3有一种使用SlidingMenu(侧滑菜单的方式),直接加你放到lib文件夹下

  2. java 更改list 某一元素?

    if(!elTd.getElementsByTag("p").isEmpty()){        int i=eduList.size();        if(i>0){ ...

  3. SGU 156. Strange Graph(欧拉路)

    时间限制:0.25s 空间限制:6M 题目描述 让我们想象一个无向图G=<V,E>.如果边(u,v)在边集E中,那么我们就说两个顶点u和v是邻接点.在这种情况下,我们也说u是v的一个邻接点 ...

  4. SGU 171.Sarov zones

    简单的贪心.优先weight最大的,优先匹配Q值大的地区 code #include <iostream> #include <algorithm> #include < ...

  5. URPF 简单流程

    主要功能是防止基于源地址欺骗的网络攻击. 路由器接口一旦使能URPF功能,当该接口收到数据报文时,首先会对数据报文的源地址进行合法性检查,对于源地址合法性检查通过的报文,才会进一步查找去往目的地址的转 ...

  6. C# winform DataGridView操作 (转)

    C# DataGridView控件动态添加新行 DataGridView控件在实际应用中非常实用,特别需要表格显示数据时.可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行.假如 ...

  7. php基础知识【函数】(7)url和ob函数

    一.URl函数 1.urlencode -- 编码 URL 字符串 2.urldecode -- 解码已编码的 URL 字符串 3.rawurlencode -- 按照 RFC 1738 对 URL ...

  8. JavaScript不可变原始值和可变的对象引用

    一.JavaScript不可变原始值 JavaScript中的原始值(undefined,null,布尔值,数字和字符串)与对象(包括了数组和函数)有着根本的区别.原始值是不可变的(undefined ...

  9. iOS中获取各种文件的目录路径和文件

    iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory ...

  10. X86架构与ARM架构比较

    引言 CPU是怎样运作的? CPU的运作与人脑的运作差不多.先谈一下人这个系统的工作方式.眼镜.耳朵.舌头.皮肤等等感觉器官接收到“触觉”,把信息传给大脑,大脑把信息处理后,把处理结果送给手.脚.嘴等 ...