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,和 ...
随机推荐
- Qt "有效且启用的储存库"问题
传送门 : https://www.cnblogs.com/SaveDictator/p/8532664.html 看就完了, 反正我好了 https://mirrors.tuna.tsinghua. ...
- C# WinForm 界面控件
C# WinForm是一种GUI应用程序框架,它允许开发人员使用各种控件来创建丰富的用户界面.以下是一些C# WinForm中常见的界面控件:这些界面控件在C# WinForm应用程序开发中非常常见, ...
- GDB调试程序 [补档-2023-07-19]
gdb调试 它是gcc的调试工具,调试工具都能干什么就不多说了. 7-1生成调试信息 在使用gcc编译c/c++的程序时,需要在编译命令中加入 -g 这一参数,它可以为你显示函数名,变量名 等 ...
- PHP截取文章内容
<?php /** * 实现中文字串截取无乱码的方法. */ function getSubstr($string, $start, $length) { if (mb_strlen($stri ...
- TDD学习笔记(二)单元测试
单元测试 定义 单元测试最早来源于Kent Beck,他在开发SmallTalk中引入了这个概念,随着软件工程学的不断发展,使得单元测试已经成为软件编程中一项非常有用的实践. 在维基百科中," ...
- SP21690 POWERUP - Power the Power Up 题解
题目传送门 前置知识 扩展欧拉定理 解法 直接对 \(a\) 和 \(b^c\) 分讨,跑一遍扩展欧拉定理就行了. 另外由于本题的特殊规定 \(0^0=1\),故需要在当 \(a=0\) 时,对 \( ...
- 从零开始的react入门教程(五),了解react中的表单,何为受控组件与非受控组件
壹 ❀ 引 我们在从零开始的react入门教程(四),了解常用的条件渲染.列表渲染与独一无二的key一文中介绍了react中常用的条件渲染操作,比如三元运算符,逻辑运算符等,结合react组件或者re ...
- JS 一篇文章弄懂Object.defineProperty,现学现用,来试试相关笔试题吧
壹 ❀ 引 早在大半年前,掘金某位用户分享的面试题整理中有一题,简述let与const区别,你能自己模拟实现它们吗?,题目意思大概如此,时间久远我也很难找到那篇文章,当时看到此题对于const实现我的 ...
- es6 快速入门 系列 —— 模块
其他章节请看: es6 快速入门 系列 模块 es6 以前,每个 javascript 都共享这一个全局作用域,随着代码量的增加,容易引发一些问题,比如命名冲突. 其他语言有包这样的概念来定义作用域, ...
- 【Unity3D】UGUI之Text
1 Text 简介 UGUI概述 中介绍了Canvas 渲染模式.RectTransform 组件.锚点(Anchor)等,本文将介绍 UGUI 中的 Text 控件. 在 Hierarchy ...