DIV1 250pt

题意:给一个整数f,则这样的正整数整数数列称为好数列:数列元素a0 >= a1 >= a2...,且a0<= f, a1 <= f-1, a2 <= f-2....。求给定f后,好数列有多少个。

解法:首先对于f = 3,{2, 1}为好数列,则补0称为{2, 1, 0}。然后,所有好数列长度都变为f。直接dp就好,d[i][j]表示长度为i,第一个元素(最大的)为j的数列有多少个。

   d[i][j] = sum(d[i-1][k])其中k <= j。

Ps:官方题解写着还可以用Catalan数做,只不过我想不通为什么可以...

tag:DP

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "FIELDDiagrams.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 CLR(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 zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(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 maxint = ; int64 d[][]; class FIELDDiagrams
{
public:
long long countDiagrams(int f){
++ f;
for (int i = ; i < f; ++ i)
d[][i] = ;
for (int i = ; i < f; ++ i){
for (int j = ; j <= f-i; ++ j){
d[i][j] = ;
for (int k = j; k <= f-i+; ++ k)
d[i][j] += d[i-][k];
}
}
return d[f-][] + d[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(); }
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 long long &Expected, const long long &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 = ; long long Arg1 = 4LL; verify_case(, Arg1, countDiagrams(Arg0)); }
void test_case_1() { int Arg0 = ; long long Arg1 = 13LL; verify_case(, Arg1, countDiagrams(Arg0)); }
void test_case_2() { int Arg0 = ; long long Arg1 = 131LL; verify_case(, Arg1, countDiagrams(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
FIELDDiagrams ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV2 550pt

题意:有两个物体运动轨迹一个为x1 = cos(t1), y1 = sin(t1), z1 = t1,另一个物体运动轨迹为x2 = vx*t + x0, y2 = vy*t + y0, z2 = vz*t + z0。只要两个运动轨迹有交点即可,不需要t1 = t2。重合交点算一个。如果有多个交点输出{0, 0, 0},一个交点输出交点坐标,没有交点输出空集。

解法:理解题意理解了半天,还搞错了。。。上网看了下才知道。。。然后,代码本身不太好写,写之前想得太简单又写错了,于是这道题做了好久- -.........

   首先,发现x1与y1的关系为x1*x1 + y1*y1 = 1,则x2*x2 + y2*y2 = 1,这样就变成了一元二次方程,当然,解出来的根还不一定满足题意,还要再判断。

Ps:官方题解说还有一种方法,就是有一个结论,要相交必然z为1/2的倍数。至于为什么,题解没有说,给了论坛的地址,看见里面的人在用英语讨论,也并不简单,我就放弃了。

tag:math

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "ParticleCollision.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 CLR(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 zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(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 maxint = ; bool ok(double t, int A, int B, int C, int a, int b, int c)
{
double x2 = A*t + a, y2 = B*t + b, z = C*t + c;
double x1 = cos(z*atan(1.0)*), y1 = sin(z*atan(1.0)*);
if (fabs(x1-x2) < eps && fabs(y1-y2) < eps) return ;
return ;
} class ParticleCollision
{
public:
vector <double> collision(int A, int B, int C, int a, int b, int c){
VD ans; ans.clear();
VD tmp;
tmp.PB (0.0); tmp.PB (0.0); tmp.PB (0.0);
double ta = A*A+B*B, tb = *(a*A + b*B), tc = a*a + b*b - ;
if (fabs(ta) < eps){
if (tc) return ans;
else{
if (C) return tmp;
if (!ok(, A,B,C,a,b,c)) return ans;
ans.PB((double)a);
ans.PB((double)b);
ans.PB((double)c);
return ans;
}
} double delta = tb*tb - * ta * tc;
if (delta < -eps) return ans;
if (fabs(delta) < eps){
double t1 = -tb / 2.0 / ta;
if (!ok(t1, A,B,C,a,b,c)) return ans;
ans.PB (A*t1+a); ans.PB (B*t1+b); ans.PB (C*t1+c);
return ans;
}
if (delta > eps){
double t1, t[] = {(-tb+sqrt(delta)) / 2.0/ta, (-tb-sqrt(delta)) / 2.0/ta};
int t_num = ;
for (int i = ; i < ; ++ i)
if (ok(t[i],A,B,C,a,b,c)){
t1 = t[i]; ++ t_num;
}
if (t_num > ) return tmp;
else if (!t_num) return ans;
ans.PB (A*t1+a); ans.PB (B*t1+b); ans.PB (C*t1+c);
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(); }
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 vector <double> &Expected, const vector <double> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = -; int Arg4 = -; int Arg5 = -; double Arr6[] = {}; vector <double> Arg6(Arr6, Arr6 + (sizeof(Arr6) / sizeof(Arr6[]))); verify_case(, Arg6, collision(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = -; int Arg4 = -; int Arg5 = ; double Arr6[] = {0.0, 1.0, 0.5 }; vector <double> Arg6(Arr6, Arr6 + (sizeof(Arr6) / sizeof(Arr6[]))); verify_case(, Arg6, collision(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; double Arr6[] = {0.0, 0.0, 0.0 }; vector <double> Arg6(Arr6, Arr6 + (sizeof(Arr6) / sizeof(Arr6[]))); verify_case(, Arg6, collision(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; int Arg4 = ; int Arg5 = ; double Arr6[] = {0.0, 0.0, 0.0 }; vector <double> Arg6(Arr6, Arr6 + (sizeof(Arr6) / sizeof(Arr6[]))); verify_case(, Arg6, collision(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
ParticleCollision ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 401(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. 使用Physics_Body_Editor获得json文件的类

    [转自]:http://www.cocoachina.com/bbs/read.php?tid=209290 工具介绍,json文件获得方法,请参考原帖 MyBodyParser.h // // My ...

  2. SGU 224.Little Queens

    时间限制:0.75s 空间限制:6M 题意 n*n(n<=10)的棋盘,求出放置m(m<=n*n)个皇后的方案数. Solution: 状态压缩+位运算  搜索. 首先我们从上往下逐行放置 ...

  3. jQuery-弹窗登录

    在jQuery中实现弹窗常要用到的方法有: width()  :元素的宽度 outerWidth()  元素的宽度 盒子的padding+border 总的宽度 scrollTop()  鼠标滚轮自上 ...

  4. jQuery选择器种类整理

    选择器概念 jQuery选择器是通过标签.属性或者内容对HTML内容进行选择,选择器运行对HTML元素组或者单个元素进行操作. jQuery选择器使用$符号,等同于jquery,例如: $(“li”) ...

  5. 由Python的super()函数想到的

    python-super *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !im ...

  6. Execl DataTime Format Number

    Excel 中日期类型所保存的值是数值型.只是设置了为日期格式,通过公式转换从而得出我们平时常用的日期内容.也很好理解这公式所要说明的意思.数值是个浮点型可以分成2部分看.整数部分:年月日(日期)小数 ...

  7. Lambda表达式中的表达式lambda和语句lambda区别

    Lambda表达式可分为表达式lambda和语句lambda 表达式lambda:表达式位于 => 运算符右侧的lambda表达式称为表达式lambda (input parameters) = ...

  8. SQL Server 2008无日志文件附加数据库

    1.新建一个同名数据库. 2.停止数据库服务,覆盖新建的数据库主文件(小技巧:最好放在同一个磁盘里面,把新建的数据库主文件删掉或移开,再把要恢复的数据库主文件剪切过去,这样就可以节省时间.) 3.启动 ...

  9. Maya+3dsMax三维建模

    Maya比较擅长动画,在人物和动物的行为活动方面比较擅长 而3ds Max在建筑物地理地图方面比较擅长,多应用于地理 将两者结合起来将会非常有用

  10. 生成mif文件的几种方法总结

    mif文件就是存储器初始化文件,即memory initialization file,用来配置RAM或ROM中的数据.生成QuartusII11.0可用的mif文件,有如下几种方式: 方法1:利用Q ...