Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
A. Fraction
题目链接:http://codeforces.com/contest/854/problem/A
题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足条件的a和b,输出a/b最大的a和b。
题目思路:首先a+b=n,那么暴力枚举i和n-i,且gcd(i,n-i)==1,由于i越大是n-i越小,则a/b的值越大。
代码:
//Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
const long long mod=1e9+;
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define sp " "
int main() {
ios::sync_with_stdio(false);cin.tie();
II n;
cin>>n;
II a,b;
for(II i=;i<=n/;i++){
if(__gcd(i,n-i)==){
a=i;b=n-i;
}
}
cout<<a<<' '<<b<<endl;
return ;
}
B. Maxim Buys an Apartment
题目链接:http://codeforces.com/contest/854/problem/B
题目意思:有n个房屋排成一排,现在其中k个房屋已经住了人,但是不知道其中的哪些房屋住进了房屋,但是小明喜欢住进邻居的房屋中有人住进的的房子里。问最少有多少个房屋满足条件,最多有多少个房屋满足条件。
题目思路:首先如果首先如果n远大于k了话,那么每一个住人的房屋,周围的两个房屋都满足小明的条件,所以我们想到每三个放一个。如果k×3>n,那么答案就是n-k,否则答案就是2×k,当然还有一些特殊情况,比如n==k还有k==0的时候,需要特判一下。
代码:
/* ***********************************************
Author :xiaowuga
Created Time :2017年10月18日 星期三 13时36分58秒
File Name :Desktop/B.cpp
************************************************ */
#include <bits/stdc++.h>
typedef long long LL;
#define endl "\n"
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();
LL n,k;
cin>>n>>k;
cout<<(k&&k<n)<<' '<<min(n-k,*k)<<endl;
return ;
}
C. Planning
题目链接:http://codeforces.com/contest/854/problem/C
题目意思:原本有n个航班,他们的起飞时间是1-n,现在机场规定在每一天的前k分钟不能有飞机起飞,那么就得有航班起飞要延误,现在给出每个航班延误一分钟所消耗的费用,问你怎么安排飞机的起飞才能使花费最少,飞机起飞时间不能比原本的要早。
题目思路:对于一个时间,用一个优先队列处理能放在当前时间的拥有每分钟最大损失的航班,这样只需要n*logn的复杂度。
题目代码:
//Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
const long long mod=1e9+;
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define sp " "
int main() {
ios::sync_with_stdio(false);cin.tie();
struct node{
LL c,id;
bool operator <(const node &m) const {
return c<m.c;
}
};
LL n,k;
vector<node>a;
cin>>n>>k;
a.resize(n+);
priority_queue<node>q;
for(LL i=;i<=n;i++){
cin>>a[i].c;
a[i].id=i;
}
vector<int>ans(n+);
for(LL i=;i<=k;i++) q.push(a[i]);
for(LL i=k+;i<=n+k;i++){
if(i<=n) q.push(a[i]);
auto now=q.top();
q.pop();
ans[now.id]=i;
}
LL sum=;
for(II i=;i<=n;i++){
sum+=(ans[i]-i)*a[i].c;
}
cout<<sum<<endl;
for(II i=;i<=n;i++) cout<<ans[i]<<' ';
return ;
}
Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)的更多相关文章
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...
- Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937
https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...
- 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...
- 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...
- Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...
随机推荐
- 如何在O(n)的时间复杂度内找出数组中出现次数超过了一半的数
方法一:每次取出两个不同的数,剩下的数字中重复出现次数超过一半的数字肯定,将规模缩小化.如果每次删除两个不同的数,这里当然不是真的把它们踢出数组,而是对于候选数来说,出现次数减一,对于其他数来说,循环 ...
- SELECT中常用的子查询操作
MySQL中的子查询 是在MySQL中经常使用到的一个操作,不仅仅是用在DQL语句中,在DDL语句.DML语句中也都会常用到子查询. 子查询的定义: 子查询是将一个查询语句嵌套在另一个查询语句中: 在 ...
- 【RF库测试】set variable if
- 与MQ通讯的完整JAVA程序
该程序实现了发送消息与读取消息的功能,见其中的 send***与get***方法.这只适合于测试,因为环境中的程序还需要对此有稍微的更改,在真实的环境中肯定是在while(true){...} 的无限 ...
- 在javaweb的项目当中实现随机数字的生成
首先,需要在javaweb的项目当中新建一个Servlet文件,然后再web.xml中配置一下: 这样运行的时候就可以通过“http://localhost:8080/Response/Respons ...
- 在 Core Data 中存取 transformable 类型的数据
本文转载至 http://imenjoe.com/2015/04/10/CoreData-transformable-20150410/ 在开发过程中有一个需要在 Core Data 中存取 NSDi ...
- PHP错误 。Parse error: syntax error, unexpected T_INLINE_HTML, expecting T_ENDSWITCH or T_CASE or T_DEFAULT
If you wan't to use the alternative syntax for switch statements this won't work: <div> <?p ...
- 通过设置P3P头来实现跨域访问COOKIE
通过设置P3P头来实现跨域访问COOKIE 实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大 ...
- TNS-12532: TNS:invalid argument,Oracle的报错信息太让人无语
TNS-12532: TNS:invalid argument,Oracle的报错信息太让人无语 现象: Tnsping报错: [oracle@unicomGZ01 admin]$ ../../bin ...
- vuex - 常用命令学习及用法整理
https://vuex.vuejs.org/zh-cn/api.html 命令 用途 备注 this.$store 组件中访问store实例 store.state.a 获取在state对象中的数据 ...