CodeForces - 197D
开场连wa三发A题,差点心态崩了,还好坚持打完了,一共A了三题
A题,判断能不能放第一个圆,能放的话,先手比赢
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1.0)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- int a,b,r;
- cin>>a>>b>>r;
- if(a>=*r&&b>=*r)cout<<"First"<<endl;
- else cout<<"Second"<<endl;
- return ;
- }
- /*********************
- *********************/
A
B题,数学题,模拟一下就好了,注意符号一定要在第一个位置,刚开始用gcd负号在第二个数那里了wa了一发
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1.0)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int gcd(int a,int b)
- {
- return b ? gcd(b,a%b):a;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- int n,m,a,b,a1,b1;
- cin>>n>>m;
- for(int i=;i<=n;i++)
- {
- cin>>a;
- if(i==)a1=a;
- }
- for(int i=;i<=m;i++)
- {
- cin>>b;
- if(i==)b1=b;
- }
- if(n>m)
- {
- if(a1*b1>)cout<<"Infinity"<<endl;
- else cout<<"-Infinity"<<endl;
- }
- else if(n<m)cout<<"0/1"<<endl;
- else
- {
- int x=gcd(a1,b1);
- a1/=x;b1/=x;
- if(a1*b1<)cout<<"-"<<abs(a1)<<"/"<<abs(b1)<<endl;
- else cout<<abs(a1)<<"/"<<abs(b1)<<endl;
- }
- return ;
- }
- /*********************
- *********************/
B
C题才是最水的题。。。搞一个记录最大的数组从后往前扫一边就出来了
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1.0)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int maxx[N];
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- string s;
- cin>>s;
- maxx[s.size()]=;
- for(int i=s.size()-;i>=;i--)
- maxx[i]=max(maxx[i+],s[i]-'');
- string ans="";
- for(int i=;i<s.size();i++)
- {
- if(maxx[i]==s[i]-'')ans+=s[i];
- }
- cout<<ans<<endl;
- return ;
- }
- /*********************
- *********************/
C
D题,dfs,如果一个点能从两个方向到达的话,那就输出yes,用一个数组记录到达的位置
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1.0)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- char ma[N][N];
- int dx[]= {,,-,};
- int dy[]= {,,,-};
- bool vis[N][N];
- int n,m,sx,sy;
- pair<int,int>v[N][N];
- bool ok(int x,int y)
- {
- if(ma[x][y]=='.'&&!vis[x][y])return ;
- return ;
- }
- void dfs(int x,int y)
- {
- int fx=x,fy=y;
- while(fx<)fx+=n;
- fx%=n;
- while(fy<)fy+=m;
- fy%=m;
- if(vis[fx][fy]&&(v[fx][fy].first!=x||v[fx][fy].second!=y))
- {
- cout<<"Yes"<<endl;
- exit();
- }
- if(!ok(fx,fy))return ;
- vis[fx][fy]=;
- v[fx][fy]=make_pair(x,y);
- for(int i=;i<;i++)
- dfs(x+dx[i],y+dy[i]);
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- cin>>n>>m;
- for(int i=;i<n;i++)
- {
- for(int j=;j<m;j++)
- {
- cin>>ma[i][j];
- if(ma[i][j]=='S')
- {
- sx=i;
- sy=j;
- ma[i][j]='.';
- }
- }
- }
- memset(vis,,sizeof vis);
- dfs(sx,sy);
- cout<<"No"<<endl;
- return ;
- }
- /*********************
- 5 5
- ##.##
- #..##
- ..###
- .#S..
- ##.##
- *********************/
D
E题,计算几何,极角排序,先dfs一遍预处理出每个节点有多少子节点,然后dfs一遍,每个区间进行极角排序(刚开始以为只需要一遍极角排序就行了,后来
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1.0)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- struct point {
- double x,y;
- int id;
- }p[N];
- point p0;
- vector<int>v[N];
- int sz[N],ans[N];
- bool comp(point p1,point p2)
- {
- double te=(p2.x-p0.x)*(p1.y-p0.y)-(p2.y-p0.y)*(p1.x-p0.x);
- if(te<)return ;
- return ;
- }
- void dfs(int u,int fa)
- {
- sz[u]=;
- for(int i=;i<v[u].size();i++)
- if(v[u][i]!=fa)
- {
- dfs(v[u][i],u);
- sz[u]+=sz[v[u][i]];
- }
- }
- void dfssort(int u,int fa,int be,int en)
- {
- for(int i=be;i<en;i++)
- if(p[i].x<p[be].x||(p[i].x==p[be].x&&p[i].y<p[be].y))
- swap(p[i],p[be]);
- p0=p[be];
- ans[p[be].id]=u;
- sort(p+be+,p+en,comp);
- int te=be;
- for(int i=; i<v[u].size(); i++)
- {
- if(v[u][i]!=fa)
- {
- dfssort(v[u][i],u,te+,te+sz[v[u][i]]+);
- te+=sz[v[u][i]];
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- int n;
- cin>>n;
- for(int i=;i<n;i++)
- {
- int a,b;
- cin>>a>>b;
- v[a].push_back(b);
- v[b].push_back(a);
- }
- for(int i=;i<n;i++)
- {
- cin>>p[i].x>>p[i].y;
- p[i].id=i+;
- }
- dfs(,-);
- // for(int i=1;i<=n;i++)cout<<sz[i]<<endl;
- dfssort(,-,,n);
- for(int i=;i<=n;i++)cout<<ans[i]<<" ";
- cout<<endl;
- return ;
- }
- /*********************
- 3
- 1 3
- 2 3
- 0 0
- 1 1
- 2 0
- *********************/
E
发现这样子节点可能会坐标倒回来,有可能相交)
CodeForces - 197D的更多相关文章
- Codeforces 197D - Infinite Maze
197D - Infinite Maze 思路:bfs,如果一个点被搜到第二次,那么就是符合要求的. 用vis[i][j].x,vis[i][j].y表示i,j(i,j是取模过后的值)这个点第一次被搜 ...
- [CodeForces - 197D] D - Infinite Maze
D - Infinite Maze We've got a rectangular n × m-cell maze. Each cell is either passable, or is a wal ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- DKLang Translation Editor
https://yktoo.com/en/software/dklang-traned Features Translation using a dictionary (so-called Trans ...
- MongoDB-4: 查询(二-数组、内嵌文档)
一.简介 我们上一篇介绍了db.collection.find()可以实现根据条件查询和指定使用投影运算符返回的字段省略此参数返回匹配文档中的所有字段,我们今天介绍了对数组和内嵌文档的查询操作,尤其是 ...
- 设置EditText明文切换
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/mingyue_1128/article/details/37651793 if (!isChecke ...
- oracle ORA-01704: string literal too long
导出数据时,在SQL拼接处,提示 oracle ORA-01704: string literal too long sql: WITH already_in AS (SELECT distinct ...
- 浅谈WebService SOAP、Restful、HTTP(post/get)请求
http://www.itnose.net/detail/6189456.html 浅谈WebService SOAP.Restful.HTTP(post/get)请求 2015-01-09 19:2 ...
- Java并发(1):synchronized
虽然多线程编程极大地提高了效率,但是也会带来一定的隐患.比如说两个线程同时往一个数据库表中插入不重复的数据,就可能会导致数据库中插入了相同的数据.今天我们就来一起讨论下线程安全问题,以及Java中提供 ...
- CNN学习笔记:线性回归
CNN学习笔记:Logistic回归 线性回归 二分类问题 Logistic回归是一个用于二分分类的算法,比如我们有一张图片,判断其是否为一张猫图,为猫输出1,否则输出0. 基本术语 进行机器学习,首 ...
- jsp验证正则表达式
jsp验证正则表达式 下面都是我收集的一些比较常用的正则表达式,因为平常可能在表单验证的时候,用到的比较多.特发出来,让各位朋友共同使用.呵呵. 匹配中文字符的正则表达式: [u4e00-u9fa5] ...
- Java架构搜集
1. 2.
- cart_购物车小程序
#author:leon product_list= [ ('iphone',5800), ('mac pro',9800), ('bike',800), ('watch',6000), ('coff ...