Codeforces Round 927 (Div. 3)(A~F)
A
第一个遇到连续两个荆棘的地方就不能再赢金币了。
所以统计连续两个荆棘之前的所有金币
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n;
cin>>n;
string str;
cin>>str;
int pos=n;
rep(i,0,n-2){
if(str[i]=='*'&&str[i+1]=='*'){
pos=i;
break;
}
}
int ans=0;
if(pos!=n){
rep(i,0,pos-1){
if(str[i]=='@'){
ans++;
}
}
}else{
rep(i,0,n-1){
if(str[i]=='@'){
ans++;
}
}
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
B
最后需要满足\(a[i]>a[i-1]\)
\(a[i]\)只能增加自身的倍数
只需要计算\(a[i]\)最终会变为自己的多少倍会严格大于\(a[i-1]\),当\(a[i-1]\)是\(a[i]\)的倍数的时候,必须再\(+1\)才能保证严格大于。
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n;
cin>>n;
vector<int>a(n+1);
rep(i,1,n){
cin>>a[i];
}
rep(i,1,n){
if(a[i]<=a[i-1]){
int cnt=a[i-1]/a[i]+1;
a[i]*=cnt;
}
}
cout<<a[n]<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
C
正着算会溢出
考虑倒着算,也就是先算最后一个留下的,然后边乘边模
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n,m;
cin>>n>>m;
struct node{
int val,pos;
bool operator<(const node&t)const{
return pos>t.pos;
}
};
vector<node>a(n+1);
rep(i,1,n){
cin>>a[i].val;
}
string str;
cin>>str;
int cnt=1;
int l=1,r=n;
rep(i,0,str.size()-1){
if(str[i]=='L'){
a[l].pos=cnt++;
l++;
}else{
a[r].pos=cnt++;
r--;
}
}
sort(a.begin()+1,a.end());
// rep(i,1,n){
// cout<<a[i].val<<' '<<a[i].pos<<endl;
// }
vector<int>ans;
int mul=1;
rep(i,1,n){
int k=a[i].val*mul%m;
ans.pb(k);
mul=k;
}
fep(i,ans.size()-1,0){
cout<<ans[i]<<' ';
}
cout<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
D
模拟题.
同花色的两两配对,是奇数的话,再用一张王去配对
判断有没有解是通过奇数牌的张数和王的张数判断。
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n;
cin>>n;
//0:C,1:D,2:H,3:S
set<int>s[4];
char c;
cin>>c;
map<char,int>mp;
mp['C']=0;
mp['D']=1;
mp['H']=2;
mp['S']=3;
map<int,char>pm;
pm[0]='C';
pm[1]='D';
pm[2]='H';
pm[3]='S';
rep(i,1,2*n){
string str;
cin>>str;
char k=str[1];
int num=str[0]-'0';
if(k=='C'){
s[0].insert(num);
}else if(k=='D'){
s[1].insert(num);
}else if(k=='H'){
s[2].insert(num);
}else{
s[3].insert(num);
}
}
int kk=0;
rep(i,0,3){
if(mp[c]==i){
continue;
}
kk+=s[i].size()%2;
}
if(kk>s[mp[c]].size()){
cout<<"IMPOSSIBLE"<<endl;
return;
}
rep(i,0,3){
if(mp[c]==i){
continue;
}
int ji=s[i].size()%2;
if(ji==1){
cout<<*s[i].begin()<<pm[i];
s[i].erase(s[i].begin());
cout<<' ';
cout<<*s[mp[c]].begin()<<pm[mp[c]];
s[mp[c]].erase(s[mp[c]].begin());
cout<<endl;
while(s[i].size()>=2){
cout<<*s[i].begin()<<pm[i];
s[i].erase(s[i].begin());
cout<<' ';
cout<<*s[i].begin()<<pm[i];
s[i].erase(s[i].begin());
cout<<endl;
}
}else{
while(s[i].size()>=2){
cout<<*s[i].begin()<<pm[i];
s[i].erase(s[i].begin());
cout<<' ';
cout<<*s[i].begin()<<pm[i];
s[i].erase(s[i].begin());
cout<<endl;
}
}
}
while(s[mp[c]].size()>=2){
cout<<*s[mp[c]].begin()<<pm[mp[c]]<<' ';
s[mp[c]].erase(s[mp[c]].begin());
cout<<*s[mp[c]].begin()<<pm[mp[c]]<<' ';
s[mp[c]].erase(s[mp[c]].begin());
cout<<endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
E
数学题。
考虑每一位对答案的贡献
\(12345\)
个位会对答案贡献\(12345\)
十位会对答案贡献\(1234\)
百位会对答案贡献\(123\)
千位会对答案贡献\(12\)
万位会对答案贡献\(1\)
然后会发现规律,将上面列竖式相加
每一位的结果就是当前位的数和前面所有数的和,然后倒着处理一下进位。
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n;
cin>>n;
string str;
cin>>str;
vector<int>s(n+1,0);
rep(i,1,n){
s[i]=s[i-1]+str[i-1]-'0';
}
fep(i,n,1){
s[i-1]+=s[i]/10;
s[i]%=10;
}
bool flag=false;
rep(i,0,n){
if(s[i]||flag){
cout<<s[i];
flag=true;
}
}
cout<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("1.in", "r", stdin);
cout.tie(0);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
F
\(dp[i][0|1]\):表示在第i个点不喂或喂猫,合法的能为猫的最大值
转移
\(nxt[i]\):在i处喂猫的话能喂猫的最有边的位置
\(cf[i]\):在i处喂猫,所能喂猫的所有数量
\(f[i][0]=max(f[i-1][0],f[i-1][1]);\)
\(f[i][1]=max(f[nxt[i]-1][1],f[nxt[i]-1][0])+cf[i];\)
\(cf[i]\)可以用差分处理一下
\(nxt[i]\)可以倒序枚举用\(nxt[i-1]\)去更新\(nxt[i]\)
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve() {
int n,m;
cin>>n>>m;
vector<int>nxt(n+2),cf(n+2);
rep(i,1,n){
nxt[i]=i;
}
rep(i,1,m){
int l,r;
cin>>l>>r;
cf[l]++;
cf[r+1]--;
nxt[r]=min(nxt[r],l);
}
//处理在每个点喂能为多少猫
rep(i,1,n){
cf[i]+=cf[i-1];
}
//处理转移的位置
fep(i,n-1,1){
nxt[i]=min(nxt[i],nxt[i+1]);
}
//dp
vector<vector<int>>f(n+1,vector<int>(2));
rep(i,1,n){
f[i][0]=max(f[i-1][0],f[i-1][1]);
f[i][1]=max(f[nxt[i]-1][1],f[nxt[i]-1][0])+cf[i];
}
cout<<max({f[n][0],f[n][1]})<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
Codeforces Round 927 (Div. 3)(A~F)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
随机推荐
- 渗透学习笔记(cookies、XSS注入)
1.cookie 插件:cookie-editor JavaScript语法: 获取:document.cookie; 设置:document.cookie="username=felix& ...
- 🛠 开源即时通讯(IM)项目OpenIM源码部署指南
OpenIM的部署涉及多个组件,并支持多种方式,包括源码.Docker和Kubernetes等.这要求在确保不同部署方式之间的兼容性同时,还需有效管理各版本之间的差异.确实,这些都是复杂的问题,涉及到 ...
- ElasticSearch实战指南必知必会:安装分词器、高级查询、打分机制
ElasticSearch实战指南必知必会:安装中文分词器.ES-Python使用.高级查询实现位置坐标搜索以及打分机制 1.ElasticSearch之-安装中文分词器 elasticsearch ...
- Origin2017、Origin2018详细安装教程
1.Origin2017安装 1.1 安装步骤: 解压安装包,打开"Origin2017"目录,双击"setup.exe"开始安装 安装步骤1,点击[下一步] ...
- yarn常用命令
1. 安装 npm install yarn -g 2. 设置淘宝镜像 yarn config set npmRegistryServer https://registry.npm.taobao.or ...
- c#树结构转npoi复杂表头
Vue 前端框架框架中采用树结构打印表头,为了前后端适配NPOI导出. 这里重点做树结构转换 NPOI 复杂表头的结构数据( 跨行.跨列),其它具体导出功能请参考 https://www.cnblo ...
- MySQL主主同步环境出现1236错误
环境: MySQL 5.7.25 主主架构 故障现象: 发现互相之间的同步均发生异常,两端均出现1236错误,在两个主节点上分别执行show slave status显示的关键信息如下: Master ...
- 树莓派安装Ubuntu系统
树莓派版本: Raspberry Pi 4B 操作系统 : Ubuntu Server 20.04_x64 树莓派官网: https://www.raspberrypi.org/ ubuntu官网: ...
- VMware 虚拟机一键去虚拟化工具
前言: 如果你想在 VMware 虚拟机里面多开玩游戏的话,但是现在大多数网游都会检测是否虚拟机,进入游戏被检测到在虚拟机中运行,游戏可能直接闪退.所以就得对 VMware 虚拟机进行去除虚拟化. 原 ...
- JS 从零手写一个深拷贝(进阶篇)
壹 ❀ 引 在深拷贝与浅拷贝的区别,实现深拷贝的几种方法一文中,我们阐述了深浅拷贝的概念与区别,普及了部分具有迷惑性的浅拷贝api.当然,我们也实现了乞丐版的深拷贝方法,能解决部分拷贝场景,虽然它仍有 ...