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. copssh加bitvise

    只是简单记录下自己在成功使用的方案: 目的:为了突破公司对网站和qq的限制 具备的条件:一台云服务器.Copssh_4.1.0.bitvise ssh client 4.62.公司电脑客户端 一.首先 ...

  2. Asp.Net MVC安全更新MS14-059导致项目编译失败

    微软最近一次安全更新MS14-059(链接:https://technet.microsoft.com/en-us/library/security/ms14-059)由于直接应用到了machine. ...

  3. Spring中的创建与销毁

    在bean中添加属性init-method="方法名" destroy-method="方法名" init-method        该方法是由spring容 ...

  4. Win异常: 除了chrome浏览器外,所有安装的软件都连不上网

    经查找资料,是LSP被篡改,恢复后使用正常. 百度百科  LSP: Layered Service Provider, 即分层服务提程序,Winsock 作为应用程序的 Windows 的网络套接字工 ...

  5. javascript——函数内部属性

    <script type="text/javascript"> //在函数内部有两个特殊的属性:arguments 和 this.arguments是一个类数组对象,包 ...

  6. yzoi1109&&viojs1042最小步数的一点看法——回文数

    Description - 问题描述 有一天,雄霸传授本人风神腿法第一式:捕风捉影..............的步法(弟子一:堂主,你大喘气呀.风:你给我闭嘴.)捕风捉影的关键是换气(换不好就会大喘气 ...

  7. 子元素的margin-top影响父元素原因和解决办法

    这个问题会出现在所有浏览器当中,原因是css2.1盒子模型中规定, In this specification, the expression collapsing margins means tha ...

  8. Application.Exit()结束程序,但线程还在的解决方法

    转自:http://bbs.51cto.com/thread-970057-1.html 出现此情况大多原因是使用了多线程编程,或者你所调用的dll使用了多线程.  我们知道,一般情况下的线程执行完指 ...

  9. Canvas实现文字粒子化,并且绕轴旋转(初号机)

    写下来发现,程序在细节上处理的很差,比如旋转的时候,在终点处有明显的撞墙感觉,以及小部分粒子存在精度差异,导致撞击后不与整体平衡. 注释全在代码中了,就不多说了,另外感觉写的旋转的规则有点怪,后续再调 ...

  10. 关于点击空白关闭弹窗的js写法推荐?

    $(document).mouseup(function(e){ var _con = $(' 目标区域 '); // 设置目标区域 ){ // Mark 1 some code... // 功能代码 ...