Codeforces Round #617 (Div. 3) 补题记录

1296A - Array with Odd Sum

题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数

思路:签到,如果本来数组的和就是个奇数,那就OK

如果不是,就需要把数组中其中一个奇(偶)数改成偶(奇)数,相当于加一减一

所以测一下这个数组如果有个奇数并且还有个偶数就行

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int num[5000];
int main ()
{
    int t,n,flag=0;
    scanf("%d",&t);
    while (t--)
    {
        int all=0;
        int a1=0,a2=0;
        scanf("%d",&n);
        for (int i=0;i<n;i++)
        {
            scanf("%d",&num[i]);
            all=all+num[i];
            if (num[i]%2==1)
                a1=1;
            if (num[i]%2==0)
                a2=1;
        }
        if (all%2==1)
            printf("YES\n");
        else
        {
            if (a1&&a2)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}

1296B - Food Buying

题意:你有一些钱,每花10块可以反1块,最多能花多少?

思路:相当于9块值10块了,但如果直接输出/9*10就WA

因为只有9块的情况下是不能返钱的,记一下就行

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main ()
{
    int t,n;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%d",&n);
        long long all=(n/9)*10;
        if (n%9==0)
            printf("%d\n",all+n%9-1);
        else
            printf("%d\n",all+n%9);
    }
    return 0;
}

1296C - Yet Another Walking Robot

题意:有一个机器人,有一个字符串,机器人按照字符串里的字母移动

问能不能去掉一个最小的连续区间,使得机器人最终到达的目的地相同?

思路:我这个是真的没想出来,看题解之后才发现,只要有两次到了相同的地方,那么机器人在中间走的一段路就是多余的

再用一个map来储存经过的点,可以用map来检测是否经过同一个点,这样就行了

但是自己写的时候总是各种玄学问题,自定义的结构体放map里无法编译...改成pair之后cf又出个WA...最后改的和题解差不多才过...

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while (t--)
    {
        int n;
        char s;
        cin>>n;
        int l=-1,r=n;
        map<pair<int, int>,int> mm;
        pair<int, int> cur={0, 0};
        mm[cur]=0;
        for (int i=0;i<n;++i)
        {
            cin>>s;
            if (s==‘L‘)
                --cur.first;
            if (s==‘R‘)
                ++cur.first;
            if (s==‘U‘)
                ++cur.second;
            if (s==‘D‘)
                --cur.second;
            if (mm.count(cur))
            {
                if (i-mm[cur]+1<r-l+1)
                {
                    l=mm[cur];
                    r=i;
                }
            }
            mm[cur]=i+1;
        }
        if (l==-1)
            cout<<-1<<endl;
        else
            cout<<l+1<<" "<<r+1<<endl;
    }
    return 0;
}

1296D - Fight with Monsters

题意:你和你的对手去打怪,按着顺序从小怪1一直到小怪n

这样打怪:你先打一下,你对手再打一下,如果在你打的时候怪死了,你得一分,你对手打的时候怪死了不得分,但是你还有几次机会可以让你的对手这次不出招,问你最多能得多少分?

思路 :好不容易除了签到又做了一道简单题...

首先,先计算在最后一轮中(也就是你和你对手都打一下这怪就死了的那一次)小怪的血量。

假如说你这次攻击能直接把怪打死,那ok,设这个怪的.ci=-1

如果不能,还是要你先打一次,然后算要让对手不出招多少次才能打死这只小怪,记到ci里

最后对所有小怪按击倒所需次数排序,遍历一遍就Ok

#include <bits/stdc++.h>
using namespace std;
struct mons
{
    int ci;
    int hp;
};
bool cmp (mons a,mons b)
{
    return a.ci<b.ci;
}
mons mon[300000];
int main ()
{
    int n,a,b,k,tem,fin=0,i;
    scanf("%d %d %d %d",&n,&a,&b,&k);
    int all=a+b;
    for (i=0;i<n;i++)
    {
        scanf("%d",&tem);
        mon[i].hp=tem%all;
        if (mon[i].hp==0)
            mon[i].hp=all;
        if (mon[i].hp<=a)
            mon[i].ci=-1;
        else
        {
            mon[i].hp=mon[i].hp-a;
            if (mon[i].hp%a==0)
                mon[i].ci=mon[i].hp/a;
            else
                mon[i].ci=mon[i].hp/a+1;
        }
    }
    sort(mon,mon+n,cmp);
    for (int i=0;i<n;i++)
    {
        if (mon[i].ci==-1)
            fin++;
        else
        {
            if (k-mon[i].ci>=0)
            {
                k=k-mon[i].ci;
                fin++;
            }
        }
    }
    printf("%d\n",fin);
    return 0;
}

原文地址:https://www.cnblogs.com/Salty-Fish/p/12263430.html

时间: 2024-07-29 12:59:26

Codeforces Round #617 (Div. 3) 补题记录的相关文章

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #627 (Div. 3) 补题

CF1324A Yet Another Tetris Problem 长度为n的数组a中有一组数,可以任意使其中一项+2,问能否使a中所有项的值相同. 感觉div.3的题目更多地在考简化问题的能力--比如原题目以俄罗斯方块作背景,让我想到的是能不能消除所有方块,导致代码很难写.但如果像上述一样简化题意,方向就很明确了:只要判断是否所有数均为偶数/均为奇数即可. CF1324A-代码 #include<cstdio> #include<iostream> #include<cs

Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. 首先我们根据一个维度(c维)对n个三元组排序,然后枚举答案在这个维度的取值. 此时序列被分成了两个部分,前半部分 满足所有c大于等于i 后半部分满足所有c严格小于i(即已有一个维度小于) 通过累计,我们知道此时前半部a维的最大值ma和b维的最大值mb. 显然可能存在的三元组答案,必然首先满足a维和

Codeforces Round #590 (Div. 3)补题

要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ? √ 解 E 待定 F 传送门 第一次接触状态压缩dp的题.这道题转换问题的思路非常巧妙. 原问题: 已知: 一个字符串,可进行不超过一次操作 操作限定: 选择某个子串,使其在原串中翻转 目的:使原串的特征值最大 串的特征值:串任意没有重复字符的子串,其包含字符的种类数 问题的转换: 首先选定一个子串a,之后再找到另一个子串b,使得a

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov