华农校赛--G,用set比较大小,缩短时间复杂度
Array C
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 581 Solved: 101
[Submit][Status][Web Board]
Description
Giving two integers and and two arrays and both with length , you should construct an array also with length which satisfied:
1.0≤Ci≤Ai(1≤i≤n)
2.
and make the value S be minimum. The value S is defined as:
Input
There are multiple test cases. In each test case, the first line contains two integers n(1≤n≤1000) andm(1≤m≤100000). Then two lines followed, each line contains n integers separated by spaces, indicating the array Aand B in order. You can assume that 1≤Ai≤100 and 1≤Bi≤10000 for each i from 1 to n, and there must be at least one solution for array C. The input will end by EOF.
Output
For each test case, output the minimum value S as the answer in one line.
Sample Input
3 4
2 3 4
1 1 1
Sample Output
6
HINT
In the sample, you can construct an array [1,1,2](of course [1,2,1] and [2,1,1] are also correct), and is 6.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
struct Node
{
long long a;
long long b;
long long c;
long long num;
int i;
bool operator < (const Node& t)const
{
return ((num>t.num)|| (num==t.num&&a<t.a)|| (num==t.num&&a==t.a&&b<t.b)||(num==t.num&&a==t.a&&b==t.b&&c<t.c)||(num==t.num&&a==t.a&&b==t.b&&c==t.c&&i<t.i));
} } node[];
set<Node>s; int main()
{
int n,m; while(scanf("%d%d",&n,&m)!=EOF)
{
long long res=;
long long sum=;
s.clear();
for(int i=; i<n; i++)
scanf("%I64d",&node[i].a);
for(int i=; i<n; i++)
scanf("%I64d",&node[i].b);
for(int i=; i<n; i++)
{
node[i].i=i;
node[i].c=node[i].a;
node[i].num=(*node[i].c-)*node[i].b;
res+=node[i].c*node[i].c*node[i].b;
sum+=node[i].a;
s.insert(node[i]);
}
// cout<<res<<endl;
Node tmp;
set<Node>::iterator iter;
for(int i=sum; i>m; i--)
{
// for(iter=s.begin(); iter!=s.end(); iter++)
// cout<<iter->num<<" ";
tmp=(*s.begin());
//cout<<tmp.num<<"***"<<res<<endl; s.erase(tmp);
res-=tmp.num;
tmp.c-=;
//out<<tmp.a<<endl;
tmp.num=(*tmp.c-)*tmp.b;
s.insert(tmp); //cout<<endl; }
printf("%lld\n",res); }
return ;
}
华农校赛--G,用set比较大小,缩短时间复杂度的更多相关文章
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
- 2016年省赛 G Triple Nim
2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...
- 2020安徽程序设计省赛 G序列游戏
2020安徽程序设计省赛 G序列游戏 有一个序列w,初始为空.再给出一个长度为m 单调递增的序列a.你需要对序列w 作如下n 次操作: (1)操作0,在序列尾部添加数字0. (2)操作1,在序列尾部添 ...
- 第八届河南省赛G.Interference Signal(dp)
G.Interference Signal Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 17 [Submit][Status ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- HUT 排序训练赛 G - Clock
Clock Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u [Submit] [Go ...
- 华中校赛 14th
https://www.nowcoder.com/acm/contest/106#question A 分类讨论 #include<bits/stdc++.h> using namespa ...
- 2015安徽省赛 G.你来擒孟获
http://xcacm.hfut.edu.cn/problem.php?id=1211 SPFA模板题目 最短路变种,从起点终点各找一次最短路相加 #include<iostream> ...
- 2016年省赛G题, Parenthesis
Problem G: Parenthesis Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 398 Solved: 75[Submit][Status ...
随机推荐
- django 实现上传文件功能
需求:自己写一个文件上传功能 代码: urls.py from django.conf.urls import url from django.contrib import admin from ap ...
- Python mongoHelper模块
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Defines a MongoOperator class and allows you to m ...
- 使用nmonchart把.nmon文件转换成html
转载:https://blog.csdn.net/zd470015321/article/details/68923280 我的环境 :centos6.6 下载地址 nmon: http://nmon ...
- xcode的svn和git使用方法
1.创建版本库:(参考:http://blog.csdn.net/itianyi/article/details/8601183) 方法:直接在windows服务器安装VisualSVN Server ...
- 外媒关注:中国版Twitter新浪微博推出微米对抗微信
Sina, China’s answer to Twitter, enters the mobile messaging battle with its own app 中国版Twitter新浪,用自 ...
- 环境变量之执行文件路径的变量PATH
当我们执行一个命令时,系统会依据PATH的设置去PATH定义的每个目录下查寻该命令的可执行文件,如果在PATH定义的目录中含有多个文件名为我们要执行的命令的可执行文件时,那么先查询到的同名命令先被执行 ...
- Spring MVC 使用拦截器 HiddenHttpMethodFilter配置Rest风格的URL
<!-- 4.使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 --> 详细使用请参考这篇博客:地址:http://blog.csdn.net/ppl ...
- java的21个技术点归纳学习
- 在ubuntu下如何搜索文件?
来自 1.whereis 文件名 特点:快速,但是是模糊查找,例如 找 #whereis mysql 它会把mysql,mysql.ini,mysql.*所在的目录都找出来.我一般的查找都用这条命令. ...
- 【Linux】touch命令
用途 touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间. 全称 touch全称即为touch 参数 -a :或--time=atime或--time=access或--time ...