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. 【ArcGIS】ArcGIS Android SDK

    1.错误提示 11-06 18:12:17.553: A/libc(11929): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 1 ...

  2. Jsoup(三)-- Jsoup使用选择器语法查找DOM元素

    1.Jsoup可以使用类似于CSS或jQuery的语法来查找和操作元素. 2.实例如下: public static void main(String[] args) throws Exception ...

  3. Nginx(五)-- 配置文件之Rewrite

    Rewrite支持URL重写 1.常用指令以及语法 1) if指令    if语法: if 空格 (condition) {}     条件:     1. “=” 来判断相等,用于字符的比较     ...

  4. Fragment切换问题

    片断一: add hind @Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) { switch (check ...

  5. iOS - UITextView在调用textViewDidChange方法,九宫格相关中文输入的问题

    问题一 iOS textView在调用 UITextViewDelegate 的 textViewDidChange方法,九宫格相关中文输入的问题 有时候,需要在textViewDidChange处理 ...

  6. <转>查看linux占用内存/CPU最多的进程

    转自 http://beginman.cn/page26/ 查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 或者top (然后按下M,注意大写) 查使用 ...

  7. java框架---->quartz的使用(一)

    Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.今天我们就来学习一下它的使用,这里会分篇章对它进行介绍.只是希望能有个人,在我说没事的时候,知道我不 ...

  8. Esper学习之十:EPL语法(六)

    在esper的文档中,epl访问数据库的配置放在了比较靠后的位置,不过为了方便各位学习,这里会先说明和数据库交互的相关配置,然后再说epl怎么访问数据库. 配置文件在官方esper包的etc文件夹下, ...

  9. css3整理--word-wrap/word-break/white-space

    word-wrap语法: word-wrap : normal | break-word normal : 默认值,单词如果单词超长,会冲出边界(单个单词超长,在当前行显示) break-word : ...

  10. LeetCode 31 Next Permutation(下一个全排列)

    题目链接: https://leetcode.com/problems/next-permutation/?tab=Description   Problem :寻找给定int数组的下一个全排列(要求 ...