codefroce 854 A.Fraction
题解:贪心,每次从能够出发的飞机中取一个最大的就好啦,用一个队列维护一下~
ac代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
struct node
{
ll v;
int id;
friend bool operator <(node a,node b)
{
return a.v < b.v;
}
}a[]; int tt[];
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i].v);
a[i].id=i;
}
ll ans=;
// cout<<"12"<<endl;
priority_queue<node> que;
int time=m;
for(int i=;i<=m;i++) que.push(a[i]);
// cout<<"123"<<endl;
while(!que.empty())
{
++time;
if(time <= n)que.push(a[time]);
node now=que.top();
que.pop();
int id=now.id;
tt[id]=time;// now time
ans+=(time-id)*a[id].v;
}
//cout<<"1234"<<endl;
printf("%I64d\n",ans);
printf("%d",tt[]);
for(int i=;i<=n;i++) printf(" %d",tt[i]);
cout<<endl;
return ;
}
codefroce 854 A.Fraction的更多相关文章
- Codeforce 854 A. Fraction
A. Fraction time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- [LeetCode] Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- 【leetcode】Fraction to Recurring Decimal
Fraction to Recurring Decimal Given two integers representing the numerator and denominator of a fra ...
- Decimal To Fraction 小数转换成分数
以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. //小数转分数 //0.3 -> 3/10, 0.2 ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环
分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...
- [LeetCode] Fraction to Recurring Decimal 哈希表
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
随机推荐
- Colab使用教程
目录 有关链接 使用GPU 切换文件夹 参考 有关链接 Google Colabratory Google Drive 使用GPU 以下两种方式都可以: "修改"->&quo ...
- 解决GitHub上传大于100M文件失败
目录 问题 解决 参考 问题 push的时候遇到以下问题: remote: error: GH001: Large files detected. You may want to try Git La ...
- ArcGIS中国工具3.2新功能
ArcGIS中国工具3.2新功能 1. 增加属性格式刷, 2. 编辑自动保存,每5分钟保存一次
- mysql 实现同一个sql查询 分页数据 和总记录数
$get_sql = "SELECT sql_calc_found_rows field1,field2 FROM table WHERE name = '1' order by add_t ...
- 002-01-RestTemplate-配置使用说明
一.概述 Spring RestTemplate 是 Spring 提供的用于访问 Rest 服务的客户端,RestTemplate 提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写 ...
- 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_12-SpringSecurityOauth2研究-JWT研究-生成私钥和公钥
3.6.3 JWT入门 Spring Security 提供对JWT的支持,本节我们使用Spring Security 提供的JwtHelper来创建JWT令牌,校验JWT令牌 等操作. 3.6.3. ...
- 123457123456#0#-----com.twoapp.KidsShiZi01--前拼后广--儿童宝宝识字jiemei
com.twoapp.KidsShiZi01--前拼后广--儿童宝宝识字jiemei
- JAVA8 JVM内存结构变了,永久代到元空间
在文章<JVM之内存结构详解>中我们描述了Java7以前的JVM内存结构,但在Java8和以后版本中JVM的内存结构慢慢发生了变化.作为面试官如果你还不知道,那么面试过程中是不是有些露怯? ...
- 【Leetcode_easy】645. Set Mismatch
problem 645. Set Mismatch 题意: solution1: 统计每个数字出现的次数了,然后再遍历次数数组,如果某个数字出现了两次就是重复数,如果出现了0次,就是缺失数. 注意:如 ...
- 【ARTS】01_37_左耳听风-201900722~201900728
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...