Codeforces Round #814 (Div. 2)(A~C)

A. Chip Game

博弈题 操作次数为奇数 B赢 否则 T赢

#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include<iomanip>
#include <cstring>
#include <unordered_map>
#define x first
#define y second
#define dashu ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int N =100010,mod=1e9+7,INF=0x3f3f3f3f;

int n,m,k;
int a[N];

void solve()
{    
        cin>>n>>m;
        
        int res=0;
        
        if(n!=1) 
        {
             if((n-1)%2==0) res+=2;
            else res++;
        }
        if(m!=1) 
        {
            if((m-1)%2==0) res+=2;
              else res++;
        }
        
        if(res%2) cout<<"Burenka"<<endl;
        else cout<<"Tonya"<<endl;
        
}
signed main()
{  
    dashu;
    int t=1;
     cin>>t;
    while(t--) solve();
	return 0;
}

B. Mathematical Circus

题意: 在偶数长度n中 两两为一组 为(a,b) 给定 n k 保证 每一组 (a+k)*b 被4整除 

数学题 通过画图寻找规律 发现 当 k%4==1 或者k%4==3 为一种

当k%4==0 无解

当k%4==2 为一种

具体看代码

​
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include<iomanip>
#include <cstring>
#include <unordered_map>
#define x first
#define y second
#define dashu ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int N =100010,mod=1e9+7,INF=0x3f3f3f3f;

int n,m,k;
int a[N];
void solve()
{    
      cin>>n>>k;
      if(k%4==1||k%4==3)
      {
          cout << "YES" <<endl;
          for(int i=1;i<=n;i+=2)
          {
              cout<<i<<" "<<i+1<<endl;
          }
      }
      else if(k%4==0) 
      {
          cout<<"NO"<<endl;
      }
     else
     {
         cout<<"YES"<<endl;
         int cnt=1;
         for(int i=1;i<n;i+=2)
         {
             if(cnt%2)
             {
                 cout<<i+1<<" "<<i<<endl;
                 
             }
             else
             cout<<i<<" "<<i+1<<endl;
             cnt++;
         }
     }
       
}
signed main()
{  
    dashu;
    int t=1;
     cin>>t;
    while(t--) solve();
	return 0;
}

​

C - Fighting Tournament

题意:n个运动员比赛 每个运动员拥有不同的力量a_{i}(1<=a_{i}<=n) 比赛先按id从前往后比赛

每一轮只将队列前两名进行比赛 赢的放队头 输的放队尾 先给出 运动员id 和 在k轮之内 该运动员赢了多少场比赛

思路:利用双端队列模拟 因为 (1<=n<=10e5) 所以最多进行10e5轮 所以使用vector的二维数组存储 id与进行到第几轮之间的关系 

分类讨论 

1. 当k>=kk 通过预处理f 直接得出答案

2. 当k<kk 通过数组g 求出 运动员最后进行到第几轮与刚刚开始比赛的轮数的差值 得出赢的场数

#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include<iomanip>
#include <cstring>
#include <unordered_map>
#define x first
#define y second
#define dashu ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int N =100010,mod=1e9+7,INF=0x3f3f3f3f;

int n,m,k;
int a[N];
int f[N];
vector<int> g[N];
void solve()
{    
        int h;
        cin>>n>>h;
        unordered_map<int,int> mp;
        deque<int> q;
        int maxv=0;
        for(int i=1;i<=n;i++)  
        {
            cin>>a[i];
            mp[a[i]]=i;
            q.push_back(a[i]);
            f[i]=0;
            g[i].clear();
        }
        int kk=0;
        while(1)
        {
            int t1=q.front();
            q.pop_front();
            int t2=q.front();
            q.pop_front();
            if(t1==n) break;
             kk++;
            if(t1>t2)
            {
                f[mp[t1]]++;
                g[mp[t1]].push_back(kk);
                q.push_front(t1);
                q.push_back(t2);
            }
            else
            {
                f[mp[t2]]++;
                g[mp[t2]].push_back(kk);
                q.push_front(t2);
                q.push_back(t1);
            }
        }
        
        
        while(h--)
        {
            int pos;
            cin>>pos>>k;
            if(k>=kk)
            {
                int res=f[pos];
                if(a[pos]==n) res+=k-kk;//特判 因为当最大的到队头之后 每一次比赛都是他赢
                cout<<res<<endl;
            }
            else if(g[pos].empty())
            {
                cout<<0<<endl;
            }
            else
            {
                int res=upper_bound(g[pos].begin(),g[pos].end(),k)-g[pos].begin();
               //找到第一次大于等于k 的下标 因为下标为0开始 不用减一
                cout<<res<<endl;
            }
        }
}
signed main()
{  
    dashu;
    int t=1;
     cin>>t;
    while(t--) solve();
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值