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

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

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

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

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

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

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

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

  8. 【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的. ...

  9. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

    A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...

随机推荐

  1. Java实现高效的枚举元素集合

    Set是Java集合类的重要组成部分,它用来存储不能重复的对象.枚举类型也要求其枚举元素各不相同.看起来枚举类型和集合是很相似的.然而枚举类型中的元素不能随意的增加.删除,作为集合而言,枚举类型非常不 ...

  2. NYOJ 116 士兵杀敌 (线段树,区间和)

    题目链接:NYOJ 116 士兵杀敌 士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描写叙述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的 ...

  3. 九度 1552 座位问题(递推DP)

    题目描述: 计算机学院的男生和女生共n个人要坐成一排玩游戏,因为计算机的女生都非常害羞,男生又很主动,所以活动的组织者要求在任何时候,一个女生的左边或者右边至少有一个女生,即每个女生均不会只与男生相邻 ...

  4. polarssl rsa & aes 加密与解密

    上周折腾加密与解密,用了openssl, crypto++, polarssl, cyassl, 说起真的让人很沮丧,只有openssl & polarssl两个库的RSA & AES ...

  5. Linux应急响应(四):盖茨木马

    0x00 前言 ​ Linux盖茨木马是一类有着丰富历史,隐藏手法巧妙,网络攻击行为显著的DDoS木马,主要恶意特点是具备了后门程序,DDoS攻击的能力,并且会替换常用的系统文件进行伪装.木马得名于其 ...

  6. 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?

    本文转载至 http://www.cnblogs.com/ios122/p/4832859.html Apple 算是最重视应用开发体验的公司了.从Xib到StoryBoard,从Auto Layou ...

  7. vc 使用ShellExecut来启动控制面板中功能模块的操作

    文件夹,文件,网址可以创建快捷方式,控制面板 中的设置也可以创建快捷方式,下面是快捷方式的命令,使用方法:在桌面或文件夹的空白处点右键,选择新建,快捷方式,在“请键入项目的位置”输入下面的命 令,然后 ...

  8. .net中单选按钮RadioButton,RadioButtonList 以及纯Html中radio的用法实例?

    .net中单选按钮RadioButton,RadioButtonList 以及纯Html中radio的用法,区别? RadioButton实例及说明: <asp:RadioButton ID=& ...

  9. Thinkphp 去除bom头 解决模版空输出问题

    <?php if (isset($_GET['dir'])){ //config the basedir $basedir=$_GET['dir']; }else{ $basedir = '.' ...

  10. Androidの疑难杂症之加载布局报Error inflating class <unknown>

    android.view.InflateException: Binary XML file line #12: Error inflating class <unknown> 出现这种错 ...