tc srm623 div2
来源:互联网 发布:如何查看手机是几g网络 编辑:程序博客网 时间:2024/05/22 04:35
A.CatchTheBeatEasy
题意:已知某时刻会掉下来的东西,问能不能全部接住
思路:水模拟
Code:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <vector>#include <cmath>using namespace std;#define maxn 1010struct node{ int x,y;}p[110];bool cmp(node a,node b){ return a.y<=b.y;}class CatchTheBeatEasy{public: string ableToCatchAll(vector<int>x,vector<int>y){ p[0].x=0; p[0].y=0; for(int i=0;i<x.size();i++) { p[i+1].x=x[i]; p[i+1].y=y[i]; } sort(p,p+1+x.size(),cmp); bool ok=true; for(int i=1;i<=x.size();i++){ if(abs(p[i].x-p[i-1].x)>p[i].y-p[i-1].y) ok=false; } if(ok) return "Able to catch"; else return "Not able to catch"; };};
B.CatAndRat
题意:一只老鼠逃到一个圆盘上,已知猫和老鼠的速度,猫在T时刻进入圆盘,问能否追上
思路:老鼠初始的时候最多跑到PI*R的地方,然后时间很好想就是delta(s)/delta(v)
Code:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <vector>#include <cmath>using namespace std;#define pi acos(-1.0)class CatAndRat{public: double getTime(int R, int T, int Vrat, int Vcat){ if(Vrat>=Vcat && R!=0) return -1.0; double tmp=T*Vrat; if(tmp>=pi*R) tmp=pi*R; return tmp/(Vcat-Vrat); }};
C.ApplesAndPears
题意:在一个row*col的果园里,找到一个面积最大的块,使得这个块里全是苹果或梨子或者空,可以移动苹果和梨子到空的地方
思路:先预处理出某一个子块中苹果梨子和空的个数,然后暴力子块的起点终点就行
Code:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <vector>#include <cmath>using namespace std;#define pi acos(-1.0)#define maxn 60int pear[maxn][maxn];int apple[maxn][maxn];int dot[maxn][maxn];class ApplesAndPears{public: int get_pear(int i,int j,int x,int y){ if(i==0 && j==0) return pear[x][y]; else if(i==0) return pear[x][y]-pear[x][j-1]; else if(j==0) return pear[x][y]-pear[i-1][y]; return pear[x][y]-pear[i-1][y]-pear[x][j-1]+pear[i-1][j-1]; } int get_apple(int i,int j,int x,int y){ if(i==0 && j==0) return apple[x][y]; else if(i==0) return apple[x][y]-apple[x][j-1]; else if(j==0) return apple[x][y]-apple[i-1][y]; return apple[x][y]-apple[i-1][y]-apple[x][j-1]+apple[i-1][j-1]; } int get_dot(int i,int j,int x,int y){ if(i==0 && j==0) return dot[x][y]; else if(i==0) return dot[x][y]-dot[x][j-1]; else if(j==0) return dot[x][y]-dot[i-1][y]; return dot[x][y]-dot[i-1][y]-dot[x][j-1]+dot[i-1][j-1]; } int getArea(vector <string> board, int K){ int row=board.size(); if(row==0) return 0; int col=board[0].size(); memset(pear,0,sizeof(pear)); memset(apple,0,sizeof(apple)); memset(dot,0,sizeof(dot)); for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ if(board[i][j]=='P') pear[i][j]=1; else if(board[i][j]=='A') apple[i][j]=1; else dot[i][j]=1; } } for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ if(j==0) ; else{ pear[i][j]+=pear[i][j-1]; apple[i][j]+=apple[i][j-1]; dot[i][j]+=dot[i][j-1]; } } } for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ if(i==0) ; else{ pear[i][j]+=pear[i-1][j]; apple[i][j]+=apple[i-1][j]; dot[i][j]+=dot[i-1][j]; } } } int ans=1; for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ for(int x=0;i+x<row;x++){ for(int y=0;j+y<col;y++){ int p=get_pear(i,j,i+x,j+y); int a=get_apple(i,j,i+x,j+y); int d=get_dot(i,j,i+x,j+y); int other_dot=get_dot(0,0,row-1,col-1)-d; int other_apple=get_apple(0,0,row-1,col-1)-a; int other_pear=get_pear(0,0,row-1,col-1)-p; if(other_dot){ if(other_dot>=p+a && p+a<=K) ans=max(ans,(x+1)*(y+1)); } if(other_dot||d){ if((x+1)*(y+1)-a<=other_apple) { int t=(x+1)*(y+1)-a-p; t+=2*p; if(t<=K) ans=max(ans,(x+1)*(y+1)); } if((x+1)*(y+1)-p<=other_pear) { int t=(x+1)*(y+1)-a-p; t+=2*a; if(t<=K) ans=max(ans,(x+1)*(y+1)); } } int total=(x+1)*(y+1); if(d==0){ if(p==total||a==total) ans=max(ans,total); } if(d==total) ans=max(ans,total); } } } } return ans; }};
0 0
- tc srm623 div2
- TC SRM 152 DIV2
- TC SRM 540 DIV2
- TC SRM 548 DIV2
- TC SRM 400 DIV2
- TC SRM 549 DIV2
- tc-551-div2
- TC SRM 552 DIV2
- tc-552-div2
- TC SRM 553 DIV2
- TC 555 div2
- TC SRM 571 div2
- TC SRM580 DIV2
- TC SRM599 div2 p950
- TC SRM573 div2 p1000
- TC SRM601 div2 p1000
- TC SRM 604 div2
- TC SRM 607 DIV2
- 白领夫妇白手起家 6年赚得两房两车
- 浅谈三层与实体
- 各个搜索引擎的User-Agent
- 如何制作一个横版格斗过关游戏(2) Cocos2d-x 2.0.4
- 公司文化
- tc srm623 div2
- rt3070驱动移植DPO_RT5572_LinuxSTA_2.6.1.3_20121022
- MySql 分页存储过程
- Ubuntu下配置Tomcat
- iOS中文网址路径转换URLEncode
- 使用BabeLua在cocos2d-x中调试Lua
- 借钱的境界:开价越低 借成的机会反而越小
- hdu2262 Quicksum
- BaseAdapter的ArrayIndexOutOfBoundsException