1.B1023

#include<cstdio>

int a[10];

int main()
{
for(int i=0;i<=9;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=9;i++)
{
if(a[i])
{
printf("%d",i);
a[i]--;
break;
}
}
for(int i=0;i<=9;i++)
{
while(a[i]--)
{
printf("%d",i);
}
}
}

2.B1020

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxv=1011; struct node
{
double price,sum,rate;
}cake[maxv]; bool cmp(node a,node b)
{
return a.rate>b.rate;
} int n;
double d; int main()
{
scanf("%d %lf",&n,&d);
for(int i=1;i<=n;i++)
{
scanf("%lf",&cake[i].sum);
}
for(int i=1;i<=n;i++)
{
scanf("%lf",&cake[i].price);
cake[i].rate=cake[i].price/cake[i].sum;
}
sort(cake+1,cake+1+n,cmp);
int cnt=1;
double ans=0;
while(d>0&&cnt<=n)
{
if(d<=cake[cnt].sum)
{
ans+=(d*cake[cnt].rate);
d=0;
}
else
{
ans+=cake[cnt].price;
d-=cake[cnt].sum;
}
cnt++;
}
printf("%.2lf\n",ans);
return 0;
}

 

3.A1037

#include<cstdio>
#include<algorithm>
using namespace std; const int maxv=1e5+5; int n,m;
int a[maxv],b[maxv]; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]);
sort(a+1,a+1+n);
sort(b+1,b+1+m);
int ans=0;
int p=1;
while(p<=n&&a[p]<0&&b[p]<0)
{
ans+=a[p]*b[p];
p++;
}
int p1=n;
int p2=m;
while(p1>=1&&p2>=1&&a[p1]>0&&b[p2]>0)
{
ans+=a[p1]*b[p2];
p1--;
p2--;
}
printf("%d\n",ans);
}

4.A1038

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std; const int maxv=1e4+4;
string s[maxv];
bool cmp(string a,string b)
{
return a+b<b+a;
} int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>s[i];
sort(s+1,s+1+n,cmp);
string ans="";
for(int i=1;i<=n;i++)
ans+=s[i];
while(ans.length()>0&&ans[0]=='0')
ans.erase(ans.begin());
if(ans.length()==0)
cout<<0<<endl;
else
cout<<ans<<endl;
return 0;
}

  

1.21 贪心入门上午PAT例题题解的更多相关文章

  1. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. POJ3614 Sunscreen 贪心入门

    题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...

  3. PAT 1031-1040 题解

    早期部分代码用 Java 实现.由于 PAT 虽然支持各种语言,但只有 C/C++标程来限定时间,许多题目用 Java 读入数据就已经超时,后来转投 C/C++.浏览全部代码:请戳 本文谨代表个人思路 ...

  4. pat甲级题解(更新到1013)

    1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...

  5. hdu2037 经典贪心入门

    今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  6. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  7. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  8. 浙大 pat 1007题解

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  9. 浙江大学Pat 1036 题解

    1036. Boys vs Girls (25) This time you are asked to tell the difference between the lowest grade of ...

随机推荐

  1. CORS (Cross Origin Resources Share) 跨域

    CORS 跨域 1 什么是跨域问题 基于安全考虑,浏览器会限制使用脚本发起任何跨域请求. 所谓的跨域请求,就是与当前页面的 http/ip/port 不一样的请求. 但在实际运用中,跨域获取数据的需求 ...

  2. HBase Master高可用(HA)

    HMaster没有单点问题,HBase中可以启动多个HMaster,通过Zookeeper的Master Election机制保证总有一个Master运行. 所以这里要配置HBase高可用的话,只需要 ...

  3. JDK源码学习LinkedList

    LinkedList是List接口的子类,它底层数据结构是双向循环链表.LinkedList还实现了Deque接口(double-end-queue双端队列,线性collection,支持在两端插入和 ...

  4. python第十六课——外部函数and内部函数

    1.外部函数&内部函数 内部函数: 定义在某个函数的内部,就是内部函数: [注意事项]: 1).内部函数可以随意使用它外部函数中的内容 2).外部函数不能使用内部函数中的内容 3).内部函数不 ...

  5. 1854. [SCOI2010]游戏【二分图】

    Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性 ...

  6. 微信授权获取用户openid前端实现

    近来,倒霉的后台跟我说让我拿个openid做微信支付使用,寻思很简单,开始干活.   首先引导用户打开如下链接,只需要将appid修改为自己的就可以,redirect_url写你的重定向url   h ...

  7. Jmeter之集合点与关联

    在Jmeter中,实现类似于LoadRunner中集合点的方法是采用同步定时器(Synchronizing Timer),而实现类似于LoadRunner中关联的方法是采用正则表达式提取器. 一.集合 ...

  8. 使用CoreAnimation 实现相机拍摄照片之后动画效果

    废话不多说,先看上效果,由于动画录制的时候帧率限制,只能将动画放慢了进行录制,更容易看到效果 这是点击开始之后代码 -(IBAction)btnStartClick:(id)sender { CABa ...

  9. PHP 回调函数call_user_func和 call_user_func_array()的理解

    call_user_func(function,param); // 第一个参数是回调函数的函数名,第二个参数是参数 call_user_func函数类似于一种特别的调用函数的方法.其主要有以下的类型 ...

  10. js 中实现aop

    http://fredrik.appelberg.me/2010/05/07/aop-js/ Aop = { // Apply around advice to all matching functi ...