Educational Codeforces Round 3
A. USB Flash Drives
水题,排序即可
int a[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) scanf("%d",&a[i]);
int ans=; sort(a,a+n);
for(int i=n-;m>;i--)
ans++,m-=a[i];
cout<<ans<<endl;
}
B. The Best Gift
本来以为要缩点,结果m<10,具体看代码
int x,n,m,b[];
ll sum;
int main()
{
memset(b,,sizeof(b)); sum=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&x),b[x]++,sum++;
ll ans=;
for(int i=;i<=m;i++) {
sum-=b[i];
ans+=sum*b[i];
}
cout<<ans<<endl;
}
C. Load Balancing
依旧是水题。。
typedef long long ll;
int a[];
int main()
{
ll ans=,sum=;
int n; scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&a[i]),sum+=a[i];
sort(a,a+n);
ll sa=sum/n+,sb=sum/n;
int na=sum%n,nb=n-sum%n;
//cout<<na<<nb<<sa<<sb<<endl;
for(int i=;i<n;i++) {
if(nb&&a[i]<=sb)
nb--,ans+=sb-a[i];
else if(na&&a[i]<=sa)
na--,ans+=sa-a[i];
}
cout<<ans<<endl;
}
D. Gadgets for dollars and pounds
题目读起来很麻烦,而且刚开始还理解错题意了。。以为每件物品既可以用英镑支付又可以用美金支付,
写完才发现样例过不了。
题目一看就是二分,第一反应以为要使用RMQ,后来发现不用也行。
首先把用美金和英镑的分开并排序,然后对于天数二分,在天数区间内遍历
得到最低美金兑换的日子,和英镑的日子,然后比较后选择花费最少burles的gadget购买
typedef long long ll;
typedef pair<int,int> pii ; #define N 200089
#define M 400009
#define f0(i,n) for(int i=0;i<(n);i++)
#define ff(i,n) for(int i=1;i<=(n);i++)
#define p_b push_back
#define m_p make_pair
#define Abs(a) (a)<0?-(a):(a)
#define Clr(a) memset(a,0,sizeof(a))
#define MID(a,b) (a+((b-a)>>1))
#define Lbit(a) (x)&(-(x))
#define X first
#define Y second
const ll INF=1LL<<-;
const int lim=<<+; int n,m,k,s;
int a[N],b[N];
vector<pii> d,p;
vector<pii> ans,tans; int judge(int day) {
tans.clear();
int d0=,d1=;
for(int i=;i<=day;i++) {
if(a[i]<a[d0]) d0=i;
if(b[i]<b[d1]) d1=i;
}
int cnt=k,pd=,pp=;
ll sb=s;
while(cnt) {
ll vd=INF,vp=INF;
if(pd<d.size())
vd=1LL*a[d0]*d[pd].X;
if(pp<p.size())
vp=1LL*b[d1]*p[pp].X; if(vd<vp) {
//ans[d[pd].Y]=d0;
tans.p_b(m_p(d[pd].Y,d0));
cnt--; sb-=vd; pd++;
}
else {
//ans[p[pp].Y]=d1;
tans.p_b(m_p(p[pp].Y,d1));
cnt--; sb-=vp; pp++;
}
}
// cout<<day<<" "<<sb<<" "<<cnt<<endl;
if(sb>=) {
ans=tans; return ;
}
return ;
}
bool cmp(pii c1,pii c2) { return c1.X<c2.X; } int main()
{ int x,y,z;
cin>>n>>m>>k>>s;
d.clear(); p.clear();
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
for(int i=;i<=m;i++) {
scanf("%d%d",&x,&y);
if(x==) d.p_b(m_p(y,i));
else p.p_b(m_p(y,i));
}
sort(d.begin(),d.end(),cmp);
sort(p.begin(),p.end(),cmp);
int l=,r=n,mid,res,flag=;
while(l<=r) {
mid=(l+r)>>;
if(judge(mid)) {
flag=; res=mid; r=mid-;
}
else l=mid+;
//cout<<l<<" "<<r<<endl;
}
if(flag) {
printf("%d\n",res);
for(int i=;i<ans.size();i++)
printf("%d %d\n",ans[i].X,ans[i].Y);
}
else puts("-1");
return ;
}
Educational Codeforces Round 3的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- [翻译][MVC 5 + EF 6] 2:基础的增删改查(CRUD)
原文:Implementing Basic CRUD Functionality with the Entity Framework in ASP.NET MVC Application 1.修改Vi ...
- ubuntu下virtualenv的复制
将一个用户下的virtualenv复制到另一个用户下.直接复制无法使用,source后的python依旧是系统自带的python. 原始env名:/home/llx/work/nn/nnenv.bak ...
- 23种设计模式全解析 (java版本)
转自:http://blog.csdn.net/longyulu/article/details/9159589 其中PHP常用的五种设计模式分别为:工厂模式,单例模式,观察者模式,策略模式,命令模式 ...
- 为 DataGridView 控件添加行号
虽然好像不经常用到,不过还是记下来防止以后用到 /// <summary> /// 为 DataGridView 控件添加行号 /// </summary> /// <p ...
- 移动端开发(使用webuploader上传图片,客户端交互,修改alert弹窗等)
之前实习做的一个移动端的页面 需要的功能有图片上传 点击客户端的返回按钮 有提示(即与客户端有交互) 遇到不少的坑 总结一下问题 1.图片上传功能 使用工具 百度的webuploader 暂时遇到的 ...
- Eclipse+Tomcat WEB开发配置
关键字:JDK,WEB,Eclipse,Tomcat OS: Windows 8.1 with update 1.下载安装JDK:http://www.oracle.com/technetwork/j ...
- STM32学习内容和计划
一.STM32学习内容(流程) 1.学习STM32开发流程 ①MDK使用.建立工程.调试等 ②库开发方法 2.学习STM32常用外设开发 ①GPIO ②中断 ③定时器 ④串口 ⑤CAN 3.学习STM ...
- UIlabel - 富文本属性
1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...
- Pentaho Data Integration (三) Pan
官网连接: http://wiki.pentaho.com/display/EAI/Pan+User+Documentation Pan Pan 是一个可以执行使用Spoon编辑的transforma ...
- A simple test
博士生课程报告 视觉信息检索技术 博 士 生:施 智 平 指导老师:史忠植 研究员 中国科学院计算技术研究所 2005年1月 目 ...