A.Escape
起点在(0,0)终点在 (x,y) 图的大小 是 (n,m)只能够往前走,往右拐,问走到终点的方案数
比赛的时候只去想dp了...后来看题解是 组合数
可是还是 不懂怎么去组合...自己组合的样例都不对TAT
好像不止一次碰到了,每次计数就想着 去 dp,还可以组合,乘法原理,加法原理..
给出光线的方向,和建筑物的左边高度,算阴影的面积并
D.Blocks
矩阵
矩阵
一个人在(0,0),速度是 1m/s ,要到终点 (100,0) 去,HP值为 x
路上会有 n 个敌人,每个敌人的攻击击范围 是 r, 每个敌人只能攻击一次,每次攻击 会使人停止 s 秒,HP减少 d
问人能不能到达终点
假设敌人都运动到终点去攻击人,所以能够攻击的时间就是 到终点的距离减去攻击范围
每次找时间最短出来的敌人出来
-------------------------------昏割线-----------------------------------------
看了题解会写...可是感觉题意读的好晦涩...而且要自己想的话还是想不出来诶...wwww
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <queue> 7 using namespace std; 8 9 struct node{ 10 double x,y,s,r,d; 11 double time; 12 friend bool operator < (node n1,node n2){ 13 return n1.time > n2.time; 14 } 15 }a[1005]; 16 17 int n; 18 double tot; 19 20 priority_queue<node> q; 21 22 void solve(){ 23 double T = 100.0; 24 while(!q.empty()){ 25 node u = q.top();q.pop(); 26 if(u.time > T) break; 27 // printf("u.x = %lf u.y = %lf u.time = %lf\n",u.x,u.y,u.time); 28 // printf("T = %lf\n",T); 29 tot -= u.d; 30 if(tot <= 0){ 31 puts("Danger!"); 32 return; 33 } 34 35 T += u.s; 36 } 37 puts("Safe!"); 38 } 39 40 int main(){ 41 while(scanf("%d",&n) != EOF){ 42 while(!q.empty()) q.pop(); 43 for(int i = 1;i <= n;i++){ 44 scanf("%lf %lf %lf %lf %lf",&a[i].x,&a[i].y,&a[i].s,&a[i].r,&a[i].d); 45 a[i].time = sqrt((a[i].x - 100.0)*(a[i].x - 100.0) + a[i].y*a[i].y) - a[i].r; 46 // printf("a[%d].time = %lf\n",i,a[i].time); 47 q.push(a[i]); 48 } 49 scanf("%lf",&tot); 50 solve(); 51 } 52 return 0; 53 }
2sqrt(2)
题解说的三分...话说到现在为止还一道三分都没有写过
给出 n1 条平行于 x 轴的直线,n2 条平行于 y 轴的直线,n3 个点
问区域内的点数大于等于1 的正方形的个数
------赛时讨论的扫描线 一脸懵逼...
可以 n3 水过去,先预处理 一个二维的前缀和,再n2 枚举 边长,再 一个 n check
正解的 n2 还不懂
--------------------------------
好久没有写求一个矩形里面的和...哇了好多次..心好痛...
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 2005; 8 9 int x[maxn],y[maxn],sum[maxn][maxn],a[maxn][maxn],have[maxn]; 10 int n1,n2,n3; 11 12 int ok(int x,int y){ 13 return x >= 1 && x < maxn && y >= 1 && y < maxn; 14 } 15 16 void solve(){ 17 sort(x+1,x+n2+1); 18 sort(y+1,y+n1+1); 19 for(int i = 1;i < maxn;i++){ 20 for(int j = 1;j < maxn;j++){ 21 sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j]; 22 } 23 } 24 int ans = 0; 25 for(int i = 1;i <= n1;i++){ 26 for(int j = i+1;j <= n1;j++){ 27 int d = y[j] - y[i]; 28 for(int k = 1;k <= n2;k++){ 29 int u = x[k]; 30 int v = x[k] + d; 31 if(!ok(u,v)) continue; 32 if(have[u] && have[v]){ 33 int x1 = u; 34 int x2 = v; 35 int y1 = y[i]; 36 int y2 =y[j]; 37 int cnt = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1]; 38 if(cnt > 0) ans++; 39 } 40 } 41 } 42 } 43 printf("%d\n",ans); 44 } 45 46 int main(){ 47 while(scanf("%d %d %d",&n1,&n2,&n3) != EOF){ 48 memset(sum,0,sizeof(sum)); 49 memset(have,0,sizeof(have)); 50 memset(a,0,sizeof(a)); 51 52 for(int i = 1;i <= n1;i++) { 53 scanf("%d",&y[i]); 54 y[i]++; 55 } 56 for(int i = 1;i <= n2;i++) { 57 scanf("%d",&x[i]); 58 x[i]++; 59 have[x[i]] = 1; 60 } 61 for(int i = 1;i <= n3;i++) { 62 int x,y; 63 scanf("%d %d",&x,&y); 64 x++;y++; 65 a[x][y] = 1; 66 } 67 68 solve(); 69 70 } 71 return 0; 72 }
不懂
枚举 一个点 跟 1,n 形成三角形,枚举两个点 跟 1 ,n 形成四边形
然后复杂度 是 n3 的...题解的代换看了好久...后来司老大跟我讲是卷积,才反应过来
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 7 typedef unsigned long long ULL; 8 const int maxn = 5005; 9 ULL f[maxn],g[maxn]; 10 11 void init(){ 12 memset(g,0,sizeof(g)); 13 memset(f,0,sizeof(f)); 14 g[0] = g[1] = g[2] = 1; 15 f[0] = f[1] = f[2] = 1; 16 for(int i = 3;i < maxn;i++){ 17 for(int j = 2;j <= i-1;j++){ 18 g[i] += f[j]*f[i-j+1]; 19 } 20 f[i] = g[i]; 21 for(int j = 2;j <= i-2;j++){ 22 f[i] += f[j]*g[i-j+1]; 23 } 24 } 25 } 26 27 int n; 28 29 int main(){ 30 init(); 31 while(scanf("%d",&n) != EOF){ 32 cout << f[n] << "\n"; 33 } 34 return 0; 35 }
不懂DFA ... 题解说的bfs ... 可是不懂什么意思
暴力枚举一边,再贪心另一边