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 ...
随机推荐
- 更新Android Studio,提示后直接点更新即可。gradle 两种更新方法,我用的第二种:手动添加gradle
直接更新即可. 更新完毕后,随即会让你更新gradle,但是会一直更新一直更新...... 解决方法: 第一种方法: 手动下载Android Studio 对应的 gradle版本,然后设置一下即可. ...
- webpack配置文件里loader的执行顺序:从下到上,从右到左; css-loader开启css模块化modules: true,
注释: options:{ importLoaders: 2 } 解决样式文件里使用@import 'xxx.xxx' 的问题 module: { rules: [{ test: /\.scss$/, ...
- Centos7 设置自定义安装nginx的systemctl启动方式
一.systemctl方式启动设置过程 1.首先创建服务配置文件(名字和路径就是这个) vim /usr/lib/systemd/system/nginx.service 2.添加配置内容 [Unit ...
- UniGui学习之部署(06)只 有Loading...,
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);begin Self.ExtRoot:='ext-6. ...
- python读取文件用b模式读取
f = open('aaa','rb') 返回的是字节 字符串编码 python中所有的字符串编码为Unicode,如果从一个文件读取字符串,那么该字符串的编码就是该文件的编码. f.tell( ...
- swift正点
Openstack Swift 原理.架构与 API 介绍 http://www.openstack.cn/?p=776 ——Openstack Swift 开源云存储技术解析 OpenStack S ...
- 九 SpringMvc与json交互
将json输出到页面: 1 加入jar包 2 配置Controller层,开启注解ResponseBody,将json发送到页面: 3 访问url 4 响应json,在形参列表里面加上注解
- 今日份学习: Docker 和 Docker的使用
笔记 Docker 能做什么? 保证开发.测试.交付.部署的环境完全一致 保证资源的隔离 启动临时的.用完即弃的环境,例如测试 迅速(秒级)超大规模部署和扩容 Docker 基本概念 镜像 image ...
- java 外卖店优先级
[问题描述] “饱了么”外卖系统中维护着 N 家外卖店,编号 1 ∼ N.每家外卖店都有 一个优先级,初始时 (0 时刻) 优先级都为 0. 每经过 1 个时间单位,如果外卖店没有订单,则优先级会减少 ...
- 扩展中国剩余定理 (ExCRT)
扩展中国剩余定理 (ExCRT) 学习笔记 预姿势: 扩展中国剩余定理和中国剩余定理半毛钱关系都没有 问题: 求解线性同余方程组: \[ f(n)=\begin{cases} x\equiv a_1\ ...