Codeforces Round 905 (Div. 3)
Codeforces Round 905 (Div. 3)
A. Morning
题意:操作:显示,向前走都为一次操作;目标:显示这四个数
思路:0->10,然后依次作差就行
#include <bits/stdc++.h>
using namespace std;
void solve(){
char a[4];
int mi=100,sum=4,b[4];
for(int i=0;i<4;i++){
cin>>a[i];
b[i]=a[i]-'0';
if(b[i]==0) b[i]=10;
}
sum+=b[0]-1;
for(int i=1;i<4;i++){
sum+=abs(b[i]-b[i-1]);
}
cout<<sum<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
B. Chemistry
题意:操作:删除一个数;目标:让该字符串变成一个回文字符串
!!!操作之后可以随意更改顺序看题不要只看一半不然会被卡
思路:一共26个字母统计出现次数,只要是偶数就可以当成回文串
#include <bits/stdc++.h>
using namespace std;
int num[27];
void solve(){
memset(num,0,sizeof(num));
int n,k;
cin>>n>>k;
int res=0;
for(int i=0;i<n;i++){
char a;
cin>>a;
int x=a-'a';
num[x]++;
}
for(int i=0;i<26;i++){
if(num[i]%2!=0) res++;
}
if(res-k>1) cout<<"NO"<<"\n";
else{
cout<<"YES"<<"\n";
}
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
C. Raspberries
题意:操作:给其中一个数+1;目标:使所有数的乘积可以被k整除
思路:k=2,3,4,5,其中3个质数为一类,4为一类
1.只要数列中有一个数的因子为k那么就能整除,不能的话就算他的mod最大的
2.如果有其中一个数+1刚好为4的倍数(特殊情况)/其中有一个数为2的倍数不为4的倍数得1,或者有两个数为2的倍数则可以直接得0,最多只需加两次,即将两个奇数分别+1然后变为偶数可直接除4.
#include <iostream>
using namespace std;
const int MAX=1e5+10;
#define int long long
int arr[MAX];
void solve() {
int n, k;
cin >> n >> k;
if (k == 4) {
int res = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
bool x=false;
for(int i=0;i<n;i++){
if((arr[i]+1)%4==0){
x=true;
}while(arr[i]%2==0){
res++;
arr[i]/=2;
if(res==2){
cout<<"0\n";
return ;
}
}
}
if(x||res==1) cout<<"1\n";
else cout<<"2\n";
} else {
int ma = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}for(int i=0;i<n;i++){
if (arr[i] % k == 0) {
cout<<"0\n";
return ;
}
ma = max(ma, arr[i] % k);
}
cout << k - ma << endl;
}
}
signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
D. In Love
题意:操作:增加或者减少一条边;结果:是否存在不重合的边
思路:只需要判断有边的右端点小于他的左端点
#include <bits/stdc++.h>
using namespace std;
map<int,int> l;
map<int,int> r;
void solve(){
char a;
int b,c;
cin>>a>>b>>c;
if(a=='+'){
l[b]++;
r[c]++;
}else{
auto x=l.find(b);
x->second--;
if(x->second==0) l.erase(x);
auto h=r.find(c);
h->second--;
if(h->second==0) r.erase(h);
}if(l.empty()||l.rbegin()->first<=r.begin()->first)
{
cout<<"No\n";
}else cout<<"Yes\n";
}
int main()
{
int t;
cin>>t;
while(t--){ solve(); }
return 0;
}
E. Look Back
题意:操作ai=ai*2;结果:整个数组为递增数组
思路:首先排除暴力,必爆long long,所以可以拿一个变量来记录前一个乘了几个2
#include <iostream>
using namespace std;
#define int long long
void solve(){
int n,res=0,a=0,b=0,num=0;
cin>>n>>a;
for(int i=1;i<n;i++) {
cin >> b;
if (b > a) {
int a2 = a;
while (a2 <= b && a2 != 0) {
a2 <<= 1;
num--;
}
num++;
num = num > 0 ? num : 0;
res += num;
a = b;
continue;
} else if (a == b) {
res += num;
continue;
} else {
int b2 = b;
while (b2 < a) {
num++;
b2*=2;
}
res += num;
a = b;
}
}
cout<<res<<endl;
}
signed main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
F. You Are So Beautiful
题意:有多少个子数组让数组中只有一个子序列和他相等
坑货,没注意是子序列,直接给我卡爆了
注意:子序列是不连续的,子数组是连续的
思路:只需要保证子数组的左端点是第一次出现在数组中,右端点是最后一次出现在数组中
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+10;
int a[MAX];
void solve(){
int n;
cin>>n;
map<int,int> mp;
for(int i=0;i<n;i++){
cin>>a[i];
mp[a[i]]=i;
}
long long int res=0,pre=0;
set<int> num;
for(int i=0;i<n;i++){
if(num.count(a[i])==0){
pre++;
num.insert(a[i]);
}if(mp[a[i]]==i){
res+=pre;
}
}
cout<<res<<endl;
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
G1. Dances (Easy version)
题意:操作:删除a[i],b[i];要求:a[i]<b[i]
思路:排序,然后删除,双指针
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+10;
int a[MAX],b[MAX];
void solve(){
int n,m;
cin>>n>>m;
a[0]=1;
for(int i=1;i<n;i++){
cin>>a[i];
}for(int i=0;i<n;i++){
cin>>b[i];
}
sort(a,a+n);
sort(b,b+n);
int ia=0,res=0;
for(int ib=0;ib<n;ib++){
if(a[ia]>=b[ib]){
res++;
}else{
ia++;
}
}
cout<<res<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Codeforces Round 905 (Div. 3)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- 《Linux基础》09. Shell 编程
@ 目录 1:Shell 简介 2:Shell 脚本 2.1:规则与语法 2.2:执行方式 2.3:第一个 Shell 脚本 3:变量 3.1:系统变量 3.2:用户自定义变量 3.2.1:规则 3. ...
- API接口设计规范
说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安全呢(防窃取)?除了https的协议之外,能不能加上通用的一套算法以及规范来保证传输的安全性呢? 下面我们 ...
- 「note」原根照抄
阶(multiplicative order) \(\textbf{Def.}\):\(\delta_m(a)\) 为最小的 \(n\) 使得 \(a^n\equiv 1\pmod m\),其中 \( ...
- 开源.NetCore通用工具库Xmtool使用连载 - 扩展动态对象篇
[Github源码] <上一篇> 介绍了Xmtool工具库中的图形验证码类库,今天我们继续为大家介绍其中的扩展动态对象类库. 扩展动态对象是整个工具库中最重要的一个设计.在软件开发过程中, ...
- vscode编写markdown
1. 需求分析 2. 环境搭建 1. 需求分析 最近在网上折腾了好久Markdown的写作环境,作为一个普通用户,总结一下个人对于Markdown写作环境的几点需求.由于本人刚接触Markdown不久 ...
- 【知识杂谈#1】Linux如何安装net-tools和sbin配置PATH
1. Linux下载net-tools 在Linux上下载net-tools包的方法可能会因你所使用的Linux发行版而有所不同.在某些现代的Linux发行版中,net-tools已经被弃用,而推荐使 ...
- 【matplotlib 实战】--柱状图
柱状图,是一种使用矩形条,对不同类别进行数值比较的统计图表.在柱状图上,分类变量的每个实体都被表示为一个矩形(通俗讲即为"柱子"),而数值则决定了柱子的高度. 1. 主要元素 柱状 ...
- Python面试题——面向对象题
1.简述面向对象的三大特性. 封装: 封装指的是把一堆数据属性与方法数据放在一个容器中,这个容器就是对象.让对象可以通过 "." 来调用对象中的数据属性与方法属性. 继承: 继承指 ...
- 常见的企业Wiki
企业Wiki(Enterprise Wiki)指适用于企业或组织内部使用的Wiki.与非企业Wiki(如著名的MediaWiki)最根本的不同点在于,企业Wiki是为企业量身定做的Wiki.通过鼓励. ...
- fasthttp + `page partial gziped cache`: 页面输出服务性能提升20%
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 接上一篇:http 中使用 gzip 输出内容时,如何预先 ...