C-Draw Grids
题意:给你一个n*m的点矩阵,每次可以连相邻两个点的一条边,直到连完无法操作的时候就输了,前提是不能连成一个多边形。问你第一个人能不能赢
思路:就是按照竖直的线走到头,然后拐回去,直到最后连玩取余2看是谁走最后一步了。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
ll n,m;cin>>n>>m;
ll ans=n*m-1;
if(ans%2==1)
{
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
return 0;
}
D-Er Ba Game
题意思路:就是题目描述中的1-5条,先判相等,然后判28,之后就按照规定去判就可以了。
代码:(队友的代码 ,我懒了)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a1,b1,a2,b2;
cin>>a1>>b1>>a2>>b2;
if(b1<a1) swap(a1,b1);
if(b2<a2) swap(a2,b2);
if(a1==a2&&b1==b2)
{
cout<<"tie"<<endl;
continue;
}
if((a1==2&&b1==8)||(a2==2&&b2==8))
{
if(a1==2&&b1==8) cout<<"first"<<endl;
else cout<<"second"<<endl;
}
else
{
if(a1==b1&&a2!=b2)
{
cout<<"first"<<endl;
}
else if(a1!=b1&&a2==b2)
{
cout<<"second"<<endl;
}
else
{
int sum1=(a1+b1)%10;
int sum2=(a2+b2)%10;
if(sum1>sum2)
{
cout<<"first"<<endl;
}
else if(sum1<sum2)
{
cout<<"second"<<endl;
}
else
{
if(b1>b2)
{
cout<<"first"<<endl;
}
else if(b1<b2)
{
cout<<"second"<<endl;
}
else
{
cout<<"tie"<<endl;
}
}
}
}
}
return 0;
}
k-Stack
题意:a数组的单点栈的长度为b数组,然后给你一些b数组的元素,问你可不可以构造出符合条件的a数组,不行的话,输出-1.
思路:看这个题目叫栈,所以可以拿栈来写,我之前还说拿vector来写呢,好像可以不过麻烦,还是太菜了
就是我们先把给出的b数组进行对应,然后其他的我们从前遍历模拟栈的操作,如果相邻的不是差1的话,就是非法的,说一下,我们栈内存的是下标,ans数组存的答案,每次压当前下标进去,栈内就是目前合法栈内的元素的下标,然后把每一次弹出的下标都从n开始赋值,然后n–就是可以符合这个单调递增的顺序。栈内若还有剩余,弹空赋值。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+7;
ll b[N],ans[N];
int main ()
{
ll n,k;cin>>n>>k;
int f=0;
for(int i=1;i<=k;i++)
{
ll x,y;cin>>x>>y;
b[x]=y;
if(y>x) f=1;
}
if(f==1){
cout<<-1<<endl; return 0;
}
stack<ll>q;
ll p=n;
for(int i=1;i<=n;i++)
{
if(b[i]==0)
{
q.push(i);
}
else
{
if(q.size()<b[i]-1)
{
cout<<-1<<endl;
return 0;
}
while(!q.empty()&&q.size()>=b[i])
{
ans[q.top()]=p--;
q.pop();
}
q.push(i);
}
}
while(!q.empty())
{
ans[q.top()]=p--;
q.pop();
}
for(int i=1;i<=n;i++)
{
cout<<ans[i]<<" ";
}
cout<<endl;
return 0;
}