当前位置: 首页 > article >正文

Codeforces Round 913 (Div. 3) A~E

目录

A. Rook 

问题分析: 

B. YetnotherrokenKeoard

问题分析:  

C. Removal of Unattractive Pairs

问题分析:  

D. Jumping Through Segments

问题分析:  

E. Good Triples

问题分析:  


A. Rook 

问题分析: 

给一个棋子将其同行同列的位置输出

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
signed main()
{IOS
use{
    string a;cin>>a;
    char x=a[0];
    int num=a[1]-'0';
    for(int i=1;i<=8;i++){
        if(i!=num)
        cout<<x<<i<<endl;
    }
    for(int i=0;i<=7;i++){
        if('a'+i!=x){
            cout<<(char)('a'+i)<<num<<endl;
        }
    }
   
}


return 0;
}

B. YetnotherrokenKeoard

 

问题分析:  

一个字符串,当当前字符为'b'时,删除新字符串最右边的 小写字符,当当前字符为'B'时删除新字符串最右边的大写字符,没有则不删除,除去'b'和'B'的其他字符添加到新字符串当中,然后输出。

可以通过栈来存储新字符串当中的大小写字符的位置,然后遇到相应的'b' or 'B',将栈顶的位置标记,最后按照标记输出原字符串的字符即可

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
signed main()
{IOS
use{
	string a;cin>>a;
	stack<int>lowi,upi;
	vct<bool>st(a.LEN);
	for(int i=0;i<a.LEN;i++){
		if(a[i]=='b'){
			st[i]=1;
			if(lowi.empty())continue;
			else st[lowi.top()]=1,lowi.pop();
		}
		else if(a[i]=='B'){
			st[i]=1;
			if(upi.empty())continue;
			else st[upi.top()]=1,upi.pop();
		}
		else {
			if(islower(a[i])){
				lowi.push(i);
			}else {
				upi.push(i);
			}
		}
	}
	for(int i=0;i<a.LEN;i++){
		if(!st[i])cout<<a[i];
	}cout<<"\n";
}


return 0;
}

C. Removal of Unattractive Pairs

 

问题分析:  

 给定字符串,如果相邻两个字符不同,可以删除这两个字符,求出最终可以剩下几个字符

我们统计每个字符的数量,为了保证最后剩下的字符个数最少,我们贪心地用个数次大的字符与个数最大的字符相抵消,因为需要维护数量的降序排序,我们选择使用大根堆来维护,我们每次弹出堆顶的两个元素,将他们互相抵消,也就是都减一,如果大于零就再放回堆当中,最终堆内会只剩下一个数,也就是最短的字符串长度

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
signed main()
{IOS
use{
	int n;cin>>n;
	string a;cin>>a;
	vct<int>cnt(26);
	for(int i=0;i<a.LEN;i++){
		cnt[a[i]-'a']++;
	}
	priority_queue<int>q;
	for(int i=0;i<26;i++){
	        if(cnt[i]!=0)q.push(cnt[i]);
	}
	while(q.size()>1){
		int x=q.top();
		q.pop();
		int y=q.top();
		q.pop();
		x--;
		y--;
		if(x>0)q.push(x);
		if(y>0)q.push(y);
	}
	if(q.empty())cout<<"0"<<endl;
	else cout<<q.top()<<endl;
}


return 0;
}

D. Jumping Through Segments

 

问题分析:  

 n个线段,每次可以选择走0~k格,第i次一定要落在第i个线段内部,要求在满足条件的情况下使得k最小.

对于k来说,k的大小对于结果的影响是单调的,故可以用二分答案,我们只需要确定第i步走出的范围能够与第i个线段有交集即可

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
signed main()
{
   IOS
   use{
       int n;
       cin >> n;
       int ans;
       vct<int> l(n + 1);
       vct<int> r(n + 1);
       for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
       int L = 0, R = 1e9;
       int mid;
       auto check = [&](int mid) -> bool {
           int dis1 = 0, dis2 = 0;
           for (int i = 1; i <= n; i++) {
               dis1 -= mid, dis2 += mid;
               if (dis1 > r[i] || dis2 < l[i]) return false;
               mmax(dis1, l[i]), mmin(dis2, r[i]);
           }
           return true;
       };
       while (L <= R) {
           mid = (L + R) >> 1;
           if (check(mid)) {
               R = mid - 1;
               ans = mid;
           } else L = mid + 1;
       }
       cout << ans << endl;
   }

   return 0;
}

E. Good Triples

 

问题分析:  

给定整数n,求出有多少个三元组满足题目条件,且若三元组的元素相同但排序不同,则 算是不同的三元组。

我们通过样例以及向下推导可知:

故满足[(n+2)\times (n+1)\div2 ]的公式,且为n各位数字得到结果的乘积

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
signed main()
{
  IOS
  use{
     string a;cin>>a;
     int ans=1;
     for(int i=0;i<a.LEN;i++){
         ans*=(a[i]-'0'+2)*(a[i]-'0'+1)/2;
     }cout<<ans<<endl;
  }

   return 0;
}

 


http://www.kler.cn/news/159838.html

相关文章:

  • 通过docker安装人大金仓数据库并挂在数据卷
  • LeetCode860. Lemonade Change
  • crui_lvgl 一个LVGL的DSL辅助工具的设想
  • Gluster ubuntu安装
  • TCP报文解析
  • C# 图片下载工具类
  • 查收查引(通过文献检索开具论文收录或引用的检索证明)
  • pycharm上传代码至gitLab
  • 逻辑漏洞之越权漏洞
  • 每天一点python——day88
  • Ubuntu 环境安装 Kafka、配置运行测试 Kafka 流程笔记
  • 案例052:用于日语词汇学习的微信小程序
  • 【laBVIEW学习】4.声音播放,自定义图标,滚动条设置,保存参数以及恢复参数
  • 前端模拟新闻列表ajax请求 mocky
  • TortoiseGit 小乌龟svn客户端软件查看仓库地址
  • 分布式锁常见实现方案
  • Android自动化测试中使用ADB进行网络状态管理!
  • CMake编译C++项目并链接动态库
  • 【Linux】信号的保存和捕捉
  • 在eclipse中安装python插件:PyDev
  • Python环境管理利器-Anaconda介绍与安装
  • 三相电表可以当作高压电表使用吗?
  • blade 项目
  • Vue学习笔记-activated和deactivated生命周期
  • 七、VMware虚拟机安装和docker容器部署项目
  • 二叉树OJ题之三
  • js基础之事件监听案例入门
  • Vue3炫酷可旋转的3D地球
  • 【500强 Kubernetes 课程】第4章 dockerfile基础篇-基本语法
  • Qt Creator 11.0.3同时使用Qt6.5和Qt5.14.2