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. 8 -- 深入使用Spring -- 2...5 Spring 3.0 新增的注解

    8.2.5 Spring 3.0 新增的注解 @DependsOn @Lazy @DependsOn :用于强制初始化其他Bean.修饰Bean类或方法,可以指定一个字符串数组作为参数,每个数组元素对 ...

  2. scala spray 概念性内容的总结

    spray 是基于 akka 的轻量级 scala 库,可用于编写 REST API 服务.了解 spray 的 DSL 后可以在很短的时间内写出一个 REST API 服务,它的部署并不需要 tom ...

  3. mysql 字符串转数据丢失精度,mysql转换丢失精度,mysql CAST 丢失精度

    mysql 字符串转数据丢失精度,mysql转换丢失精度,mysql CAST 丢失精度 =============================== ©Copyright 蕃薯耀 2017年9月1 ...

  4. mongo数据库查询结果不包括_id字段方法

    db.GPRS_PRODUCT_HIS_FEE.find({"条件字段" : "412171211145135"},{_id:0}) db.GPRS_PRODU ...

  5. iOS开发-Autolayout小结

    昨天重点学习了下Autolayout,把以前没有吃透的概念重新理解了下,现在感觉整个人都是棒棒哒. 上一个项目是使用计算坐标代码的方式来布局UI界面,这种方式的缺点在于当苹果发布新尺寸设备时需要重写代 ...

  6. Selenium 异常处理

    在使用 Selenium 的过程中,难免会遇到一些异常,例如超时.节点未找到等错误,我们可以使用 try...except... 语句来捕获各种异常 更多异常类参考官网:https://seleniu ...

  7. 64位Oracle 11g 使用PL/SQL

    Oracle 11g和PL/SQL安装完后,发现打开PL/SQL并不能连接Oracle数据库! [第一回合]完败! 先是在网上找解决方法,说是需要使用Net Configuration Assista ...

  8. 通过java的i/o机制进行图片流的存储以及对网络图片的存储

    存储内地图片思路:首先把原有的图片以流的方式读取出来,再以流的方式存储到目标文件: package imgStream; import java.io.*; public class ImgStrea ...

  9. 处理i18n国际电话区号的代码实践

    本文转载至 http://adad184.com/2015/08/18/practice-in-i18n-dialling-code/ 前言 上周在忙产品的国际化(i18n)的问题 其中一个很重要的地 ...

  10. 关于bat中使用rar压缩命令

    数据库备份,导出的dmp 文件比较大,需要压缩,压缩后大小能变为原来十分之一左右吧. 写的是批处理的语句,每天调用,自动导出dmp 文件,压缩删除原文件. 首先写下路径 先将压缩软件的路径写入系统的环 ...