转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
A:博弈问题,一个矩形中,放入半径等于r的圆,谁不能放,就输了。
一开始比较茫然,仔细想一下发现有对称性质,一开始在中心放入一个圆,便将矩形分为对称区域,对手放入一个圆,则自己可以在对称的区域相同的位置放入圆。
#include<iostream>
#include<cstring>
#include<queue>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<stack>
#define N 105
using namespace std;
int main(){
int a,b,r;
while(scanf("%d%d%d",&a,&b,&r)!=EOF){
if(2*r>a||2*r>b)
printf("Second\n");
else
printf("First\n");
}
return 0;
}
B:取极限问题,比较简单,想清楚所有的情况就OK了
#include<iostream>
#include<cstring>
#include<queue>
#include<string>
#include<cstdio>
#include<algorithm>
#define N 105
using namespace std;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int main(){
int n,m;
int a[105],b[105];
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=0;i<=n;i++)
scanf("%d",&a[i]);
for(int j=0;j<=m;j++)
scanf("%d",&b[j]);
if(n==m){
if(a[0]*b[0]<0)
printf("-");
printf("%d/%d\n",abs(a[0])/gcd(abs(a[0]),abs(b[0])),abs(b[0])/gcd(abs(a[0]),abs(b[0])));
}
else if(n>m){
if(a[0]*b[0]<0)
printf("-");
printf("Infinity\n");
}
else
printf("0/1\n");
}
return 0;
}
C:选出字典序最大的子序列,维护一个单调栈就OK了
#include<iostream>
#include<cstring>
#include<queue>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<stack>
#define N 105
using namespace std;
char str[200005];
stack<char>s,ans;
int main(){
while(scanf("%s",str)!=EOF){
while(!s.empty())
s.pop();
while(!ans.empty())
ans.pop();
int len=strlen(str);
for(int i=0;i<len;i++){
if(s.empty())
s.push(str[i]);
else{
if(str[i]<=s.top())
s.push(str[i]);
else{
while(1){
if(s.empty())
break;
if(str[i]>s.top())
s.pop();
else
break;
}
s.push(str[i]);
}
}
}
while(!s.empty()){
ans.push(s.top());
s.pop();
}
while(!ans.empty()){
printf("%c",ans.top());
ans.pop();
}
printf("\n");
}
return 0;
}
D:一个无限大的地图,问是否能无限走下去。
对于每一个位置,如果可以从多个位置到达,则说明进入了循环,便将是可以无限移动的。
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<vector>
#define eps 1e-10
#define LL long long
#define LD long double
#define pi acos(-1.0)
using namespace std;
struct Node{
int x,y;
}s,u,v,tt;
int n,m;
int way[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
bool flag[1505][1505];
int vis[1505][1505][2];
char str[1505][1505];
bool bfs(){
queue<Node>que;
que.push(s);
memset(flag,false,sizeof(flag));
while(!que.empty()){
u=que.front();
que.pop();
for(int i=0;i<4;i++){
v=u;
v.x+=way[i][0];
v.y+=way[i][1];
tt.x=((v.x%n)+n)%n;
tt.y=((v.y%m)+m)%m;
if(str[tt.x][tt.y]=='#')
continue;
if(flag[tt.x][tt.y]){
if(v.x!=vis[tt.x][tt.y][0]||v.y!=vis[tt.x][tt.y][1])
return true;
}
else{
flag[tt.x][tt.y]=true;
vis[tt.x][tt.y][0]=v.x;
vis[tt.x][tt.y][1]=v.y;
que.push(v);
}
}
}
return false;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=0;i<n;i++){
scanf("%s",str[i]);
for(int j=0;j<m;j++)
if(str[i][j]=='S'){
s.x=i;
s.y=j;
}
}
printf("%s\n",bfs()?"YES":"NO");
}
return 0;
}
E:构造???还没搞定,待更新。
分享到:
相关推荐
Codeforces Round #723 (Div. 2).md
上面代码跑出来的dp[n][m]是0,然后从(1,1)(1,2)(2,2)(2,3)这样的相与值是k (看懂ans+k是啥应该就懂了) 代码: int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int ans=(1&...
传送门 题意: 开始位置在0,问能否跳到n+1位置 每步只能跳d 在1——n每个位置有方向,L,R,求d的最小值 思路: 只用找相邻两个R之间的最大值即可 代码: #include #include ...typedef long long l
就是把所有相等的数放到一个vector里,如果他出现大于2次,看最远的间距是否大于2即可,找到一个就可以 代码: #include #include #include #include #include #include #include #include #include #include #...
长度为n的字符串包含n−2n−2n−2个aaa和222个bbb,求按照字典序排列输出第kkk个字符串 解题思路 第一个bbb在倒数第二位有1个字符串,在倒数第三位有2个字符串…在倒数第nnn位时有n−1n-1n−1个字符串 可以根据第一...
E. Cyclic Components 题目链接-E. Cyclic Components 题目大意 给你nnn个点和mmm条边,求所构成图中单圈环的个数 ...并查集并查集并查集 很明显单圈环每个点的度都为222,所以我们可以用数组cnt[]记录每个点的度,...
Codeforces Round #629 (Div. 3) E.Tree Queries (DFS) 思路:若ai 在路径上 ,则ai的父结点一定在路径上,若ai是路径上某个结点的子结点,则ai的父结点一定在路径上,综上只需考虑ai的父节点就行了。对每个ai判断...
给两两节点放一个数字(0~n-2 唯一) 给你一棵树,求所有任意两节点相连的路以外的路上的数字的最小值最小 思路 构造 若一个点连了三条边及以上,则这个点的边从最小值开始赋值。其他边从最大点开始赋值。 证明:一...
给一个长度为n的数组,两种操作,一个是把任意一个ai变成ai+2a_i变成a_i+2ai变成ai+2,另一个是如果所有数都大于0,可以把所有数减1,问通过这些操作能否把所有数变为0 思路: 如果任意两个数之差为奇数,那么就...
输入一个正整数x,找出这样的2个正整数a和b,使得gcd(a,b)+lcm(a,b)=x 解题思路 找最特殊的情况a=1,b=x-1即可 这样a,b两个数最大公因数为1,最小公倍数x-1,满足题意√ 附上代码 #include #define int long long #...
B. Longest Palindrome time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Returning back to problem solving, Gildong is now studying about ...
将所有数字看成2进制,从最高位看起,如果第i位上为1的数只有一个的话,那么这个数必然对答案有贡献,就把它排在第一个,后面任意排。 例:11,6,4,0 二进制表示为:1011,110,100,0 右起第四位为1的只有1011,...
C(n-2,i-1)*C(j-1,n-2)*(i-1) __ j: n-1 -> m 我们发现内层循环,每次只是j加一,我们就可以只用一次组合数剩下的用差量表示 对于外层循环同理 只有(i-1) * C(n-2,i-1) i会每次加一。我们也只算一次剩下的用差量...
传说门 刚好今晚是中国场! 其实这道题比较水,但当时思路错,一心想着化简公式,浪费了好多时间a....#pragma GCC optimize(2) #include #define ll long long #define endl '\n' using namespace std; const int manx=
传送门 题意: 找规律,题意就是有多少种方式填充该图形 画两个就发现,输出n即可 代码: #include #include #include #include #include #include #include #include ...#define SZ(x) ((int)(x)
A #include using namespace std; typedef long long ll; int main(){ int t; cin>>t; while(t--){ ll x; cin>>x; cout<<1>>t; while(t--){ st.clear(); ll n; cin >>n;... ll re
题目链接:B. Longest Palindrome 题目 Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse....
惭愧,前几天刚学的dfs序判祖先关系都忘了用。。 这题我们先把所有点都变成父亲节点(根节点不变),这样只需要判所有节点是否在一条链上。 由于判断x是y的祖先:需要满足:st[x]<...const int M = 2e5+