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. mysql大数据量使用limit分页,随着页码的增大,查询效率越低下

    1.   直接用limit start, count分页语句, 也是我程序中用的方法: select * from product limit start, count当起始页较小时,查询没有性能问题 ...

  2. android scheme打开天猫,淘宝

    直接上代码 Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); /* Str ...

  3. KMP算法用JavaScript实现

    KMP算法是字符串匹配的经典算法,简称 看毛片, 理论知识请直接看阮一峰老师的这篇文章,我看完文章之后尝试对算法进行了实现. 一句话总结KMP算法的核心思想:就是跳过已经对比的部分 而KMP算法的核心 ...

  4. 集合之ArrayList

    一.ArrayList概述 ArrayList是实现List接口的动态数组,所谓动态就是它的大小是可变的.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类 ...

  5. Oracle 数据库纯dos代码操作

    1. 安装成功后进入DOS界面操作 在进行以下操作时,需启动Oracle服务. A.进入sql界面:开始--运行--cmd:输入sqlplus 回车 提示输入正确的用户名和密码 B.开始—>所有 ...

  6. PAT02-线性结构3 Reversing Linked List

    题目:https://pintia.cn/problem-sets/1010070491934568448/problems/1037889290772254722 先是看了牛客(https://ww ...

  7. Selenium 设置代理chrome

    1.1. 连接无用户名密码认证的代理 from selenium import webdriver chromeOptions = webdriver.ChromeOptions() chromeOp ...

  8. Kafka设计解析(二)Kafka High Availability (上)

    转载自 技术世界,原文链接 Kafka设计解析(二)- Kafka High Availability (上) Kafka从0.8版本开始提供High Availability机制,从而提高了系统可用 ...

  9. ZOJ 3212 K-Nice(满足某个要求的矩阵构造)

    H - K-Nice Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

  10. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...