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. Android MVP模式

    转自http://segmentfault.com/blogs,转载请注明出处Android MVP Pattern Android MVP模式\[1\]也不是什么新鲜的东西了,我在自己的项目里也普遍 ...

  2. ECMA中关于if与else的关系的一句英文,感觉比较经典

    Each else for which the choice of assocated if is ambiguous shall be associated with the nearest pos ...

  3. 高性能、高并发TCP服务器(多线程调用libevent)

    from:http://blog.csdn.net/i_am_jojo/article/details/7587838 本文讲述的TCP服务器是模仿memcache中的TCP网络处理框架,其中是基于l ...

  4. c语言"a<b<c"条件值的判定

    示例代码: #include <stdio.h> int main() { , b = , c = ; ; while (a<b<c) { t = a; a = b; b = ...

  5. 诡异的XmlSerializer属性字段Specified

    自动生成代码时,往往会为一个字段假设为 * , 生成另一个bool型字段: *Specified: 如: [Serializable] public class A { [XmlElement] pu ...

  6. 摩尔斯电码(Morse Code)Csharp实现

    摩尔斯电码,在早期的"生产斗争"生活中,扮演了很重要的角色,作为一种信息编码标准,摩尔斯电码拥有其他编码方案无法超越的长久生命.摩尔斯电码在海事通讯中被作为国际标准一直使用到199 ...

  7. 查找类class所在的jar包

    CTRL+SHIFT+R 意思是输入关键字搜索当前工程的 对象. CTRL+SHIFT+T 输入关键字搜索当前工程的类.

  8. HTML DOM Select 对象

    Select 对象 Select 对象代表 HTML 表单中的一个下拉列表. 在 HTML 表单中,<select> 标签每出现一次,一个 Select 对象就会被创建. 您可通过遍历表单 ...

  9. webserver<2>

    #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wai ...

  10. Word添加带圈文字

    这个在项目有编号李没有,只能一个一个输入 A.开始------------字体里选择带圈的字符号 B.插入,符号里选编号