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

  1. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

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

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

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

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

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

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

  7. Codeforces Round #368 (Div. 2)

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

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

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

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

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

随机推荐

  1. Navicat连接mysql时候出现1251错误代码

    出现1251错误代码 是因为mysql8.0的密码加密方式与之前5.0的不同 如果是字母式的密码 比如root 可能会出现这种情况 1.先通过命令行进入mysql的root账户 Enter passw ...

  2. Python内置模块-logging

    一.初识logging模块 import logging logging.debug("debug message") #级别最低,只有在诊断问题时才有兴趣的详细信息. loggi ...

  3. NSNotFound

    1.在数组或者字典中查找元素时,没有查到系统用NSNotFound表示.比如下面例子,应该养成这种编程习惯,可以减少因为’超标’而闪退的情况. if ([self.departmentNameArra ...

  4. 服务端OLEVARIANT数据之后传输

    将OLEVARIANT数据流化,然后对流进行压缩,还原成OLEVARIANT以后再发送. procedure StreamToVariant(Stream: TStream; var V: OLEVa ...

  5. C#中SqlDataAdapter的使用小结---转载

    C#中SqlDataAdapter的使用小结 转载 叁木-Neil 最后发布于2018-06-07 21:29:39 阅读数 8275 收藏 展开 SqlDataAdapter对象 一.特点介绍1.表 ...

  6. JS监听video视频播放时间

    采用原生时间监听element.addEventListener(event, function, useCapture) //监听播放时间 var video = document.getEleme ...

  7. docker学习笔记-06:自定义DockerFile生成镜像

    一.自定义centos的DockerFile 1.从阿里源里拉的centos镜像新建的容器实例中,没有vim编辑器和ifconfig命令,所以自定义centos的DockerFile,创建自己想要的镜 ...

  8. Vmware tools变灰不能点击的问题

    1. 挂载镜像文件,虚拟机->设置->硬件->CD/DVD.右边“连接”下面选择“使用IOS镜像文件”,浏览选择虚拟机包目录下面linux.iso 2. 挂载成功后,在虚拟机右下角c ...

  9. [GoogleInterview]连续子序列问题

    Before the Beginning 本文为 Clouder 原创文章,原文链接为 https://www.codein.icu/gci-subarray/,转载时请将本段放在文章开头显眼处.如进 ...

  10. 刷题55. Jump Game

    一.题目说明 题目55. Jump Game,给定一组非负数,从第1个元素起,nums[i]表示你当前可以跳跃的最大值,计算能否到达最后一个index.难度是Medium. 二.我的解答 非常惭愧,这 ...