Codeforces Round #611 (Div. 3)
原题面:https://codeforces.com/contest/1283
A.Minutes Before the New Year
题目大意:给定时间,问距离零点零分还有多久?
分析:注意一下特判0,0就好了。
代码:
t = input()
t = int(t)
for i in range(t):
h, m = input().split()
h = int(h)
m = int(m)
if h == and m == :
print()
continue
ret = *
ret -= h *
ret -= m
print(ret)
B.Candies Division
题目大意:分糖果,得到糖果数最多的人的糖果数与得到糖果数最少的人的数量之差不能大于一。并且得到糖果数量最多的人不得多于人数的一半。
分析:简单的数学题,比较一下得到糖果数最多与最少相等的情况和得到糖果数最多比最少多一的情况即可。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t;
ll n, k;
cin >> t;
while (t--) {
cin >> n >> k;
ll average = n / k;
ll remain = n - average * k;
cout << average * k + min(remain, k / ) << endl;
}
return ;
}
C.Friends and Gifts
题目大意:每个人都要给其他一个人一个礼物,并且每个人都要收到一个礼物。请你构造一种合法的赠送礼物的方法,使得每个人都赠送非自己的人一个礼物,并且从其他人那里收到一个礼物。
分析:贪心的构造题?不知道啊,反正乱搞就过了。先把没收到礼物的找出来,再把没赠送礼物的找出来,题目保证这两类人数相等,再按合法的方法构造就行了。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int f[maxn],in[maxn],out[maxn];
vector<int> need_out;
vector<int> need_in;
int main() {
int n;
cin >> n;
for (int i = ; i <= n; i++)
cin >> f[i];
for (int i = ; i <= n; i++) {
if (!f[i])
out[i] = ;
else
out[i]++, in[f[i]]++;
}
for (int i = ; i <= n; i++) {
if (!in[i]) {
need_in.push_back(i);
}
}
for (int i = ; i <= n; i++) {
if (!out[i]) {
need_out.push_back(i);
}
}
sort(need_in.begin(), need_in.end(), less<int>());
sort(need_out.begin(), need_out.end(), less<int>());
bool flag = true;
while (flag) {
flag = false;
int sz = need_in.size();
for (int i = ; i < sz; i++) {
if (need_in[i] == need_out[i]) {
flag = true;
swap(need_out[need_out.size() - ], need_out[i]);
}
}
for (int i = sz - ; i >= ; i--) {
if (need_in[i] == need_out[i]) {
flag = true;
swap(need_out[], need_out[i]);
}
}
}
for (int i = ; i < need_in.size(); i++) {
f[need_out[i]] = need_in[i];
}
for (int i = ; i <= n; i++) {
cout << f[i] << (i == n ? '\n' : ' ');
}
return ;
}
D.Christmas Trees
题目大意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小。
分析:对于每个点,肯定是先选取距离为1的,然后再选取距离为2的,以此类推。但是有的点不一定选得到,因此我们可以用队列来存储那些可以到达的点,这样就可以得知这个题跑个bfs可行。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
typedef long long ll;
queue<pair<int,int>> q;
map<int,bool> vis;
int x[maxn];
vector<int> ans;
int main() {
int n, m;
cin >> n >> m;
for (int i = ; i <= n; i++) {
cin >> x[i];
vis[x[i]] = true;
}
for (int i = ; i <= n; i++) {
if (!vis[x[i] - ]) {
q.push(make_pair(x[i] - , ));
vis[x[i] - ] = true;
}
if (!vis[x[i] + ]) {
q.push(make_pair(x[i] + , ));
vis[x[i] + ] = true;
}
}
ll ret = ;
while (ans.size() < m) {
pair<int, int> u = q.front();
ans.push_back(u.first);
ret += u.second;
q.pop();
if (!vis[u.first - ]) {
vis[u.first - ] = true;
q.push(make_pair(u.first - , u.second + ));
}
if (!vis[u.first + ]) {
vis[u.first + ] = true;
q.push(make_pair(u.first + , u.second + ));
}
}
cout << ret << endl;
for (int i = ; i < m; i++)
cout << ans[i] << (i == m - ? '\n' : ' ');
return ;
}
E.New Year Parties
题目大意:有n个人住在一些房子里,有的人住在同一个房子里。每个人可以选择搬去他的房子左边那个房子或者右边那个房子,亦或是不搬。问这些人最少住几个房子和最多住几个房子。
分析:最多就是尽可能得让所有房子都有人嘛,最少就是尽可能得集中这些人。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int x[maxn],n,xx,xxx[maxn];
int main() {
cin >> n;
for (int i = ; i <= n; i++)
cin >> xx, x[xx]++, xxx[xx]++;
for (int i = n + ; i >= ; i--) {
if (x[i] > ) {
x[i - ]++;
x[i]--;
}
}
for (int i = ; i <= n; i++) {
if (x[i] > ) {
x[i + ]++;
x[i]--;
}
}
int most = ;
for (int i = ; i <= n + ; i++) {
if (x[i]) most++;
}
int least = ;
for (int i = ; i <= n + ;) {
if (xxx[i]) {
i += ;
least++;
} else {
i++;
}
}
cout << least << " " << most << endl;
return ;
}
Codeforces Round #611 (Div. 3)的更多相关文章
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #611 (Div. 3) E
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past ...
- Codeforces Round #611 (Div. 3) C
There are nn friends who want to give gifts for the New Year to each other. Each friend should give ...
- Codeforces Round #611 (Div. 3) D
There are nn Christmas trees on an infinite number line. The ii -th tree grows at the position xixi ...
- 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 ...
随机推荐
- 关联容器:unordered_map详细介绍
版权声明:博主辛辛苦苦码的字哦~转载注明一下啦~ https://blog.csdn.net/hk2291976/article/details/51037095 介绍 1 特性 2 Hashtabl ...
- day20-Python运维开发基础(装饰器 / 类中的方法 / 类的方法变属性)
1. 装饰器 / 类中的方法 / 类的方法变属性 # ### 装饰器 """ 定义:装饰器用于拓展原来函数功能的一种语法,返回新函数替换旧函数 优点:在不更改原函数代码的 ...
- 【C++初学者自学笔记一】(把自己刚学到的东西做一下总结,如果有哪些地方不足请留言指正)
这是我写的第一个博客关于C++的一些笔记,我不会写的太深奥,因为这样很多人会看不懂(我刚开始学C语言深受其害).个人觉得C++这门语言有些类似于C语言但是有些函数的用法还是有不一样的.C语言中的头文件 ...
- LeetCode刷题--21.合并两个有序链表(简单)
题目描述 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1 -> 2 -> 4 ,1 -> 3 -> 4 输出:1 ...
- 【快学springboot】11.整合redis实现session共享
前言 这里都是基于前面的项目基础上的.springboot整合redis非常的方便,这也是springboot的宗旨,简化配置.这篇文章就教大家如何使用springboot整合redis来实现sess ...
- drugs
1. 摘录:未来简史 2. 毒品禁药扫盲 3. 毒品争议 4. 部分毒品列表 5. 影视作品里常出现的几种毒品 1. 摘录:未来简史 第一章 人类的新议题 幸福快乐的权利 (P36) 人们喝酒是为了遗 ...
- 解决modelsim破解在win10下无法生成license
显示没有找到mgls.dll,此时,这个教程能够帮助你. 1.右击搜索结果cmd,选择以管理员身份运行 2. 打开win64(进入安装目录的win64),也就是两个破解文件所在的路径,输入cd win ...
- 关于MySQL连接Navicat Premium 12失败的解决方法
出现问题的原因:MySQL8.0之后更换了加密方式,而这种加密方式客户端不支持 解决:更改加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysq ...
- Day3-M-Cable master POJ1064
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...
- 1-7SpringBoot之表单验证@Valid
SpringBoot提供了强大的表单验证功能实现,给我们省去了写验证的麻烦: 这里我们给下实例,提交一个有姓名和年龄的表单添加功能, 要求姓名不能为空,年龄必须是不小于18 : 我们先新建一个Stud ...