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 ...
随机推荐
- Day11 - I - 取石子游戏 HDU - 2516
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出"Second win".先取者胜输出&q ...
- yii 框架 – 安全站点和非安全站点的 URL 管理
在本文中我将描述怎么管理安全站点和非安全站点的 URL 管理. 安全站点的内容使用httpsSSL (安全套接字层) 协议发送,而非安全站点使用http协议.为了描述简单,我们称前者https内容/页 ...
- 为什么直接ping知乎的ip不能访问知乎的网站,而百度就可以?
结论: 简单的说,就是baidu有钱. 正文: 大型网站依靠自身稀稀落落的服务器很难满足网页"秒开"的用户需求,会加入CDN加速的队伍. 当用户访问 http://www.zhih ...
- NSNotFound
1.在数组或者字典中查找元素时,没有查到系统用NSNotFound表示.比如下面例子,应该养成这种编程习惯,可以减少因为’超标’而闪退的情况. if ([self.departmentNameArra ...
- CentOS6.9安装redis
目录 Centos6.9下的Redis安装和配置(最简易方式) redis客户端登录方式 Centos6.9下的Redis安装和配置(最简易方式) 在服务器上创建一个目录/service,然后下载re ...
- Java 虚拟机程序监控工具软件
jdk自带的查看工具(jdk安装目录/bin) .Java VisualVM .jconsole
- HDU 5524:Subtrees
Subtrees Accepts: 60 Submissions: 170 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 13107 ...
- 「SDOI2015」寻宝游戏
传送门 Luogu 解题思路 发现一个性质: 对于所有的宝藏点 \({a_1,a_2...a_k}\) ,按照dfs序递增排列,答案就是: \(dis(a_1, a_2) + dis(a_2, a_3 ...
- 修饰者模式(装饰者模式,Decoration)
1. 装饰者模式,动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更加有弹性的替代方案. 2.组合和继承的区别 继承.继承是给一个类添加行为的比较有效的途径.通过使用继承,可以使得子类在拥有 ...
- 防止SQL注入的登录页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/T ...