华农校赛--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 ...
随机推荐
- Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax
So you want to spit out some XML from SQL Server into a file, how can you do that? There are a coupl ...
- C++如何禁止掉对象的复制操作
最容易想到的是将拷贝构造函数与赋值函数声明为private.但是,private只是说外部不能直接调用,但是可以间接通过类的成员函数与友元函数对其访问.那么怎么办呢? ---->在类中,允许声明 ...
- hadoop常见问题总结1
本文地址:http://www.cnblogs.com/archimedes/p/hadoop-problem1.html,转载请注明源地址. 问题1:http://localhost:50030 H ...
- Vue.js前后端同构方案之准备篇——代码优化
收录待用,修改转载已取得腾讯云授权 导语 目前Vue.js的火爆不亚于当初的React,本人对写代码有洁癖,代码也是艺术.此篇是准备篇,工欲善其事,必先利其器.我们先在代码层面进行优化,对我们完成整个 ...
- (C++)浅谈多态基类析构函数声明为虚函数
主要内容: 1.C++类继承中的构造函数和析构函数 2.C++多态性中的静态绑定和动态绑定 3.C++多态性中析构函数声明为虚函数 1.C++类继承中的构造函数和析构函数 在C++的类继承中, 建立对 ...
- ASP.NET HTTP500错误怎么办
如图所示,HTTP500错误. 第一步:"开始"->"设置"->"控制面板"->"管理工具"-> ...
- ASP.NET缺少程序集引用怎么办
如下所示,提示缺少Windows的引用,在using System.Windows.Forms;有一个下划线 错误代码为: 错误 1 命名空间"System"中不存在类 ...
- ArcGIS Add-In调试无法重新生成
在调试ArcGIS Add-In时,出现错误:无法注册程序集"……\Projects\ArcGISAddIn\ArcGISAddIn\bin\Debug\ArcGISAddIn.dll&qu ...
- 在linux下安装mysql
1.下载mysql 下载地址: http://dev.mysql.com/downloads/mysql/5.5.html#downloads 2.进入系统后,检测是否安装mysql #rpm -qa ...
- Python中的作用域
Python中的作用域 Python 中,一个变量的作用域总是由在代码中被赋值的地方所决定的. 当 Python 遇到一个变量的话他会按照这样的顺序进行搜索: 本地作用域(Local)→当前作用域被嵌 ...