原题面: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. Python基础-4 运算符

    运算符 运算符:以1 + 2为例,1和2被称为操作数,"+" 称为运算符. Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 ...

  2. Spring Boot + MyBatis + PostgreSql

    Maven构建项目 1.访问http://start.spring.io/ 2.选择构建工具Maven Project.Spring Boot版本1.3.6以及一些工程基本信息,点击“Switch t ...

  3. gradle 打包所有依赖 Invalid signature file digest for Manifest main attributes(转)

    1.打包所有依赖: // 指定main函数的类 jar { manifest { attributes "Main-Class": "com.baeldung.fatja ...

  4. RGB 和 YUV 的转换公式

  5. php中$_REQUEST、$_POST、$_GET的区别和联系小结

    php中$_REQUEST.$_POST.$_GET的区别和联系小结 作者: 字体:[增加 减小] 类型:转载   php中有$_request与$_post.$_get用于接受表单数据,当时他们有何 ...

  6. VS2017+EF6+MySQL8.0配置(.Net Framework 4.5)

     开发环境Vs2017 运行环境:.Net Framework 4.5(win7专业版 64位) 1.下载安装mysql数据库版本:mysql-8.0.19-winx64 ----数据库版本貌似跟My ...

  7. mmap 与 munmap

    功能描述 mmap(memory map) 将一个文件或其他对象映射进内存. 文件被映射到多个page上, 若文件的大小不是所有page的大小之和, 最后一个page不被使用的空间将会被清零. mum ...

  8. 吴裕雄--天生自然python机器学习实战:K-NN算法约会网站好友喜好预测以及手写数字预测分类实验

    实验设备与软件环境 硬件环境:内存ddr3 4G及以上的x86架构主机一部 系统环境:windows 软件环境:Anaconda2(64位),python3.5,jupyter 内核版本:window ...

  9. ubuntu 文件操作

    linux的文件目录是一棵目录树,默认起始位置在主文件夹(/home/city),里面有若干子文件(视频.图片.下载.桌面等) 一.文件路径(目录操作) 1.绝对路径:从根目录/写起,完整的.详细的描 ...

  10. linux之我的互联网面试经验

    互联网面试想必是每个学计算机的学生必不可少的环节,无论你的项目经验再多,你不准备基础知识,也还是无济于事.首先来说说关于工作的事情. 三年前,那时候我还是刚刚快要大四毕业的小鲜肉,那时候有个超大的招聘 ...