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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. [碎碎念]和ljf老师聊天得到的一些启发,希望大家一起来吹水

    关于写这个小文 和ljf老师聊天得到的一些启发,希望能够总结出来方便回顾,并且我觉得这些想法有一定的普适性,可以供大家参考. 疑问 我的疑问是,我现在主要在做fuzz+pwn,能够进行漏洞挖掘,以及w ...

  2. MIT6.s081/6.828 lectrue4:page tables 以及 Lab3 心得

    不管是计算机组成还是操作系统,虚拟内存都是其中的重要内容,所以这一节我会结合 CSAPP 第九章:虚拟内存 来一起复习(顺便一说,CSAPP 这一节的 lab 是要求设计一个内存分配器,也是很有意思的 ...

  3. Docker 安装Redis 无法使用配置文件设置密码问题

    背景 最近开发需要使用各种组件,如果都到开发机上安装,会占用电脑资源较多.所以使用docker容器来安装这些组件.例如 redis .mongodb.mysql.rabitmq.elasticsear ...

  4. 《SQL与数据库基础》21. 分库分表(一)

    目录 分库分表(一) 拆分策略 垂直拆分 垂直分库 垂直分表 水平拆分 水平分库 水平分表 技术实现 MyCat概述 概念介绍 环境准备 目录介绍 MyCat入门 配置 分片配置(schema.xml ...

  5. 【NestJS系列】连接数据库及优雅地处理响应

    前言 Node作为一门后端语言,当然也可以连接数据库,为前端提供CURD接口 我们以mysql为例,自行安装mysql TypeORM TypeORM 是一个ORM框架,它可以运行在 NodeJS.B ...

  6. WPF学习 - 闭坑(持续更新)

    坑1:自定义控件设计原则: 既然称之为控件,那么就必定有界面与行为两部分. 界面就是展示给用户看的,用于承载类的属性.方法.事件等. 行为就是类的方法,以及这些方法需要用到的属性.字段等. WPF设计 ...

  7. 【项目源码】基于JSP动漫论坛的设计与实现

    动漫论坛项目主要用于实现动漫爱好者的互相交流,基本功能包括:注册用户.登录.浏览帖子.发布新帖.回复帖子.等.本系统结构如下: (1)普通用户: 注册用户:如果用户为非会员用户,通过注册,经审核通过之 ...

  8. 多主架构:VLDB技术论文《Taurus MM: bringing multi-master to the cloud》解读

    本文分享自华为云社区<多主创新,让云数据库性能更卓越>,作者: GaussDB 数据库. 华为<Taurus MM: bringing multi-master to the clo ...

  9. 对某个接口进行限流 以 Aop 注解的形式绑定接口 用redis实现

    简单的针对某个接口进行限流,如果需要整体限流的话还是建议在网关上面或者服务器上面动手Controller: @LimitRequest(count = 1,time = 60 * 1000 * 2) ...

  10. 编译nw-node版本的插件

    编译nw-node版本的插件 下载nwjs对应版本的nodejs 原始源码目录 yh@yh:~/addon$ tree . ├── addon.cc ├── binding.gyp ├── CppLi ...