链接:https://ac.nowcoder.com/acm/contest/12606/D
来源:牛客网

题目描述

Your friend has secretly picked N consecutive positive

integers between 1 and 100, and wants you to guess if their sum is

even or odd.

If the sum must be even, output 'Even{\tt Even}Even'.  If the sum must be odd, output 'Odd{\tt Odd}Odd'. If the sum could be even or could be odd,

output 'Either{\tt Either}Either'.

输入描述:

The input is a single integer N with 1≤N≤101 \le N \le 101≤N≤10.

输出描述:

Output a single word. The word should be 'Even{\tt Even}Even', 'Odd{\tt Odd}Odd', or
'Either{\tt Either}Either', according to the rules given earlier.

示例1

输入

复制1

1

输出

复制Either

Either

示例2

输入

复制2

2

输出

复制Odd

Odd

思路分析:因为是在1到100内的连续整数个数,当是连续奇数个的时候,这个时候奇偶是无法确定的,当时连续四个或者四个倍数的时候,一定是偶数个,其余的条件是奇数

#include<bits/stdc++.h>
using namespace std;
int main()
{int n;cin>>n;if(n%2==1){cout<<"Either"<<endl;}else if(n%4==0){cout<<"Even"<<endl;}else{cout<<"Odd"<<endl;}return  0;
}

链接:https://ac.nowcoder.com/acm/contest/12606/F
来源:牛客网

题目描述

To save money, Santa Claus has started hiring other animals besides reindeer to

pull his sleigh via short term 'gig' contracts. As a result, the actual
animals that show up to pull his sleigh for any given trip can vary greatly in
size.

Last week he had 2 buffalo, 37 voles and a schnauzer. Unfortunately, both
buffalo were hitched on the left side and the entire sleigh flipped over in
mid-flight due to the weight imbalance.

To prevent such accidents in the future, Santa needs to divide the animals for
a given trip into two groups such that the sum of the weights of all animals in
one group equals the sum of the weights of all animals in the other. To make
the hitching process efficient, Santa is seeking an integer target weight t
such that all animals that are lighter than t go in one group and those
heavier than t go into the other. If there are multiple such t, he wants
the smallest one. There's one small wrinkle: what should be done if there some
animals have weight exactly equal to t? Santa solves the problem this way: if
there are an even number of such animals, he divides them equally among the two
groups (thus distributing the weight evenly). But if there are an odd number of
such animals, then one of those animals is sent to work with the elves to make
toys (it is not put in either group), and the remaining (now an even number)
are divided evenly among the two groups.

输入描述:

Input describes a list of animals' weights. The first line contains an integer
m (2≤m≤1052 \le m \le 10^52≤m≤105), indicating the number of animals. The next m lines
each have a positive integer. These are the weights of the animals (in ounces).
Animals weighing more than 20 00020\,00020000 ounces are too big to pull the sleigh so
no given weight will exceed this maximum.

输出描述:

Output the smallest integer target weight t, as described above. It's
guaranteed that it is possible to find such an integer.

示例1

输入

复制4 3 6 1 2

4
3
6
1
2

输出

复制4

4

示例2

输入

复制4 11 8 3 10

4
11
8
3
10

输出

复制10

10

示例3

输入

复制2 99 99

2
99
99

输出

复制99

99

题意理解:

输入n个数,分为两组,要求两组数的和相等,给定一个数t,要求t比一组的全部数大,比另一组的全部数小,找出最小的t。

tip:当t和n个数中的数有相同时,如果个数为偶数,就把他们分别分到两组,如果个数为奇数,就剔除一个,变成偶数,按偶数处理。

直接处理前后缀和,当某个i的i-1的前缀和i+1的后缀的值一样大小的时候,答案就是i

accode:

#include<iostream>
#include<memory>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;const int N = 1e5+10;int n,m,a[N];
ll pre[N],back[N],cnt[N];
int main()
{cin>>n;for(int i=1;i<=n;i++){cin>>a[i];cnt[a[i]]++;}for(int i=1;i<=1e5;i++){pre[i]=pre[i-1]+cnt[i]*i;}for(int i=1e5;i>=1;i--){back[i] = back[i+1] + cnt[i]*i;}for(int i=1;i<=1e5;i++){if(pre[i-1]==back[i+1]){printf("%d\n",i);break;}} return 0;
}

H On Average They’re Purple

链接:https://ac.nowcoder.com/acm/contest/12606/H
来源:牛客网

题目描述

Alice and Bob are playing a game on a simple connected graph with N nodes and M edges.

Alice colors each edge in the graph red or blue.

A path is a sequence of edges where each pair of consecutive edges have a node in common. If the first edge in the pair is of a different color than the second edge, then that is a ''color change.''

After Alice colors the graph, Bob chooses a path that begins at node 1 and ends at node N. He can choose any path on the graph, but he wants to minimize the number of color changes in the path. Alice wants to choose an edge coloring to maximize the number of color changes Bob must make. What is the maximum number of color changes she can force Bob to make, regardless of which path he chooses? changes she can force Bob to make, regardless of which path he chooses?

输入描述:

The first line contains two integer values N and M with 2≤N≤100 0002 \le N \le 100\,0002≤N≤100000 and 1≤M≤100 0001 \le M \le 100\,0001≤M≤100000. The next M lines contain two integers aia_iai​ and bib_ibi​ indicating an undirected edge between nodes aia_iai​ and bib_ibi​ (1≤ai,bi≤N1 \le a_i, b_i \le N1≤ai​,bi​≤N, ai≠bia_i \not= b_iai​​=bi​).All edges in the graph are unique.

输出描述:

Output the maximum number of color changes Alice can force Bob to make on his route from node 1 to node N.

示例1

输入

复制3 3 1 3 1 2 2 3

3 3
1 3
1 2
2 3

输出

复制0

0

示例2

输入

复制7 8 1 2 1 3 2 4 3 4 4 5 4 6 5 7 6 7

7 8
1 2
1 3
2 4
3 4
4 5
4 6
5 7
6 7

输出

复制3

3

题意理解:

题目吹的很厉害,但是根本其实就是一个最短路减一,或者是bfs即可

#include<iostream>
#include<memory>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 1e5+10;
const int INF = 0x3f3f3f;
const int maxn = 100005 * 2;

int n,m;
bool vis[maxn] = {0};
vector<int> vec[maxn];
int dis[maxn] = {0};
queue<ll> q;

int main()
{
    cin>>n>>m;
    int u,v;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    q.push(1);
    vis[1] = 1;
    
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int v:vec[u]){
            if(vis[v]) continue;
            vis[v] = 1;
            
            dis[v] = dis[u]+1;
            q.push(v);
        }
    }
    
    
    cout<<dis[n] - 1 <<endl;
    return 0;    
}

链接:https://ac.nowcoder.com/acm/contest/12606/E
来源:牛客网

题目描述

You are given a list of integers x1,x2,…,xnx_1, x_2, \ldots, x_nx1​,x2​,…,xn​ and a number k.

It is guaranteed that each i from 1 to k appears in the list at least once.

Find the lexicographically smallest subsequence of x that contains
each integer from 1 to k exactly once.

输入描述:

The first line will contain two integers n and k, with
1≤k≤n≤200 0001\le k\le n\le 200\,0001≤k≤n≤200000.
The following n lines will each contain an integer xix_ixi​ with
1≤xi≤k1\le x_i\le k1≤xi​≤k.

输出描述:

Write out on one line, separated by spaces, the lexicographically smallest
subsequence of x that has each integer from 1 to k exactly once.

示例1

输入

复制6 3 3 2 1 3 1 3

6 3
3
2
1
3
1
3

输出

复制2 1 3

2 1 3

示例2

输入

复制10 5 5 4 3 2 1 4 1 1 5 5

10 5
5
4
3
2
1
4
1
1
5
5

输出

复制3 2 1 4 5

3 2 1 4 5

因为取牌是有后效性的,也就是说你要提前处理出所有数值的牌还剩多少张,然后就是用单调栈进行贪心了。我们要维护单调栈内递增,这样可以做到当前最优的状态,然后配合预处理的牌的张数进行出栈。有一个地方要特殊注意一下,如果这个数值已经在栈内了,那就直接过。

acccode:

#include<iostream>
#include<memory>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;const int N = 2e5+10;int a[N],cnt[N];
int stk[N],tp,vis[N];int main()
{int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];cnt[a[i]]++;}for(int i=1;i<=n;i++){if(!vis[a[i]])//不在栈中的时候{while(tp && a[stk[tp]] >a[i] && cnt[a[stk[tp]]]){vis[a[stk[tp]]] = 0;tp--;}stk[++tp] = i;vis[a[i]] = 1;}cnt[a[i]]--;//如果数值已经在栈中了就直接跳过}for(int i=1;i<=tp;i++)cout<<a[stk[i]]<<" ";return 0;
} 

2021年度训练联盟热身训练赛第一场相关推荐

  1. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  2. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

  3. 2021年度训练联盟热身训练赛第五场

    2021年度训练联盟热身训练赛第五场 链接:https://ac.nowcoder.com/acm/contest/13926 A Binary Seating #include<bits/st ...

  4. 2021年度训练联盟热身训练赛第八场

    目录 2021年度训练联盟热身训练赛第八场 A-Fire on Field 题意 思路 代码 B-Gene Tree 题意 思路 代码 I-Thread Knots 题意 思路 代码 J-Triang ...

  5. 2021年度训练联盟热身训练赛第三场(待补)

    文章目录 前言 一.Circuit Math(后缀表达式---栈&&fgets) 二.Diagonal Cut(gcd最大公因数,数论) 三.expected primary-expr ...

  6. 2021年度训练联盟热身训练赛第一场 E Early Orders 思维 + 栈

    传送门 题意: 给nnn个数,一个kkk,求aaa中包含1−k1-k1−k且字典序最小的子序列. 思路1: 记p[i]p[i]p[i]为iii出现的最后位置,让后维护一个栈,当这个数不在栈里时将其入栈 ...

  7. 2021年度训练联盟热身训练赛第一场 H题On Average They‘re Purple(BFS)

    题意: 给你一些联通关系,问Bob先选择一些路径(1~n)联通,Alice在路径上染色,Bob的目的是选择一些路径使得染色变化最小,对于Alice来说,需要使得在Bob选择的(1−n1-n1−n)d的 ...

  8. 2021年度训练联盟热身训练赛第一场 A.Weird Flecks, But OK (最小覆盖圆)

    题目链接: A.Weird Flecks, But OK 题解 从XOY.YOZ.XOZ三个面,寻找最小圆覆盖,只要满足存在一个面的点被圆覆盖即可,答案就是每个面的最小圆的最小值. 代码 #inclu ...

  9. 2021年度训练联盟热身训练赛第一场 (除G,K外所有)

    传送门 A Weird Flecks, But OK An artist who wanted to create an installation where his works appeared t ...

  10. J.This Ain‘t Your Grandpa‘s Checkerboard (简单遍历)(2021年度训练联盟热身训练赛第一场)

    传送门 题目要求: ①每一行的黑色方块数量相等  ②每一列的黑色与白色的方块数相等   ③ 每一行或列没有连续3个会以上的相同色块. 思路:直接遍历统计一遍即可. 代码实现: #include< ...

最新文章

  1. 2007年100款最佳安全工具谱
  2. 让PHP更快的提供文件下载 【转】
  3. 几种xml读取方法比较
  4. 计算硼原子的基态能级B---库仑排斥能
  5. leetcode(3)——414. 第三大的数(C++中的 set,::作用符号,迭代器),628 三个数的最大乘积(sort函数的用法)
  6. 两条水位线的业务需求分析-Interval JOIN方案(转载+自己分析整理)
  7. rsa PHP用法,RSA常见用法整理
  8. trackbar控件显示刻度值_安卓自定义电平流图形控件
  9. 自定义Json解析工具
  10. python之路--面向对象之封装
  11. 华为ensp ftp 上传下载
  12. 设置模式之UML中的类图及类图之间的关系
  13. MTK_on_line_FAQ_SW_ALPS_System+-+Bootup
  14. BASH SHELL ls -l 输出了什么
  15. 外卖点餐APP效果图
  16. Bandizip官网最新下载 中文,绿色版 Bandizip下载
  17. 比较好的文档翻译软件-哪个翻译软件最精准
  18. postgresql等待锁排查——ShareLock ExclusiveLock
  19. kylin官方给出的优化 以及各个步骤容易出现的问题
  20. npm安装报no such file or directory原因和解决方法

热门文章

  1. 贪心算法介绍及合理性证明
  2. 中国金融业已成为外资超级提款机
  3. 马云说不看学历?程序员现实:大专投阿里被拒,浙大投了就面试!!!
  4. mvc iis设置默认首页无效
  5. Java Web学习笔记(二)密码一致性检测的实现
  6. WiFi密码别问了,这神器帮你搞定一切!
  7. 建议在RaspberryPi 4b 上使用 64位官方镜像
  8. iOS-An Apple ID verification code is required to sign in. Type your password followed by the verific
  9. 期货是赚谁的钱(期货赚的钱是从哪里来的)
  10. 抖音文案怎么写吸引人情感,2021抖音经典短句