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的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [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 ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. (redis缓存更新策略)postgres 9.4.1 && redis 3.7.0 && redis_fdw_REL9_4_STABLE

    首先下载redis_fdw,这里要注意下载的版本.(https://github.com/pg-redis-fdw/redis_fdw) 一开始,我下载了REL9_4_STABLE_pre2.8版本, ...

  2. 在后台代码中引入XAML的方法

    本文将介绍三种方法用于在后台代码中动态加载XAML,其中有两种方法是加载已存在的XAML文件,一种方法是将包含XAML代码的字符串转换为WPF的对象. 一.在资源字典中载入项目内嵌资源中的XAML文件 ...

  3. STM32库函数实现方法

    一.概述 1.调用STM32库函数配置与直接配置寄存器 ① 直接配置寄存器 使用过51单片机的朋友都知道为了将IO口配置成某种特殊功能或者配置中断控制,我们先将需要如下步骤: 根据需要配置功能计算值- ...

  4. App 性能分析

    关键因素: ---- Instrument 性能分析神器 1. 启动时间 应用启动时间长短对用户第一次体验至关重要,同时系统对应用的启动.恢复等状态的运行时间也有严格的要求,在应用超时的情况下系统会直 ...

  5. combo下拉列表选择

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. kill -9杀掉nginx主进程、reload失败解决办法

    前言: 无意间使用 kill -9 命令杀掉了nginx的主进程,当我再次使用 ./nginx -s reload 重新刷新nginx的时候,一直出现了下面的错误信息: nginx: [alert] ...

  7. Java 判断操作系统类型(适用于各种操作系统)

    Java 判断操作系统类型(适用于各种操作系统) 最近一段时间写一个授权的程序,需要获取很多信息来保证程序不能随意复制使用,必须经过授权才可以. 为了限制用户使用的操作系统,必须有统一的方法来获取才可 ...

  8. redis基本命令的演示:

    import redis r = redis.Redis(host='127.0.0.1', port=6379,db = 0) #查看匹配redis的数据 r.keys() #查看redis的大小 ...

  9. python manage.py shell之后的一些错误:

    1. 在执行python manage.py shell之后的一些错误: wyl@wyl:~/myobject$ python manage.py shell /usr/lib/python2.7/d ...

  10. COGS 577 蝗灾 [CDQ分治入门题]

    题目链接 昨天mhr神犇,讲分治时的CDQ分治的入门题. 题意: 你又一个w*w正方形的田地. 初始时没有蝗虫. 给你两个操作: 1. 1 x y z: (x,y)这个位置多了z只蝗虫. 2. 2 x ...