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. 【转】.NET Core基于. csproj 配置文件发布项目

    一.前言 .NET工具链在最新的Preview3版本中,引入了新的MSBuild项目系统,项目文件又回归了.csproj的XML文件来管理,项目文件.包引用.程序集引用..NET Core工具集.发布 ...

  2. 【译文】Web Service 众所周知的问题

    1. 什么是web service Web Service是一种网络程序间的通信方式,它允许开发者用API方式暴露自己的业务逻辑功能,这样,其他开发者可以使用它 2. Web Service的特性 互 ...

  3. ElasticSearch 简单的 搜索 聚合 分析

    一. 搜索1.DSL搜索 全部数据没有任何条件 GET /shop/goods/_search { "query": { "match_all": {} } } ...

  4. Java基础加强之并发(三)Thread中start()和run()的区别

    Thread中start()和run()的区别 start() : 它的作用是启动一个新线程,新线程会执行相应的run()方法.start()不能被重复调用.run()   : run()就和普通的成 ...

  5. [IDE123] Intellij Idea 快捷键

    Ctrl+Shift+N,可以快速打开文件 Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Sh ...

  6. php官网下载的chm手册,源码字号太小的问题解决

    首先,到官方网站上下载chm格式的文档,地址如下: http://php.net/downloads.php 如图,点击荧光笔标出链接 然后就可以看到各种语言版本的文档手册,可以选择中文版,并带有笔记 ...

  7. (转)CentOS 7 —— /etc/rc.local 开机不执行 - 解决方法

    chmod +x /etc/rc.d/rc.localsystemctl enable rc-local.service Note: rc.local is obsolete. ----------- ...

  8. 学习笔记—MapReduce

    MapReduce是什么 MapReduce是一种分布式计算编程框架,是Hadoop主要组成部分之一,可以让用户专注于编写核心逻辑代码,最后以高可靠.高容错的方式在大型集群上并行处理大量数据. Map ...

  9. Golang从文件服务器获取图片显示到客户端

    一.需求 A(客户端)--------------->B(服务端)-------------->C(文件服务器) 在客户端需要显示图片列表,但是不想C(文件服务器)的地址被暴露出来,所以现 ...

  10. 卸载JLink驱动弹出“could not open INSTALL.LOG file”的解决方法

    我的操作环境是Windows 10 64位,JLink驱动的版本是V4.96. 最近好久不用STM32了,打算把JLink驱动卸载掉,但是无论是用JLink驱动自带的卸载程序还是控制面板来卸载,都会弹 ...