PAT A1009-1012
A 1009 Product of Polynomials (25 point(s))
读懂题意就行。
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm> using namespace std;
typedef struct NODE
{
int exp;
double coe;
NODE(){exp = ; coe = ;}
NODE(int e, double v):exp(e),coe(v){}
}node;
vector<node> poly1, poly2;
double rstPoly[]={};
int main()
{
int N, tmpExp;
double tmpCoe;
cin >> N;
for(int i = ; i < N; ++ i)
{
cin >> tmpExp >> tmpCoe;
poly1.push_back(NODE(tmpExp, tmpCoe));
}
cin >> N;
for(int i = ; i < N; ++ i)
{
cin >> tmpExp >> tmpCoe;
poly2.push_back(NODE(tmpExp, tmpCoe));
}
for(int i = ; i < poly1.size(); ++i)
for(int j = ; j < poly2.size(); ++ j)
rstPoly[poly1[i].exp+poly2[j].exp] += poly1[i].coe*poly2[j].coe;
int cnt = ;
for(int i = ; i < ; ++ i)
if(rstPoly[i] != )
cnt++;
cout << cnt;
for(int i = ; i >= ; -- i)
if(rstPoly[i] != )
{
printf(" %d %.1f", i, rstPoly[i]);
}
return ;
}
A 1010 Radix (25 point(s))
这道题目相当有趣,坑的莫名其妙,哈哈哈。
注意:1.数的范围,10位数字,int 不够用
2.超时,因而不能从小到大递增取进制数
3.二分法,最大进制和最小进制的确定
4.超限,在找进制数的过程中,过大的进制数会发生超限,注意这种情况
5.待确定进制数只有一位,此时需要注意取最小进制
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm> using namespace std;
long long toNum(char c)
{
return isdigit(c) ? c-'' : c-'a'+;
}
long long strRadixToNum(string tmpStr, long long radix)
{
long long tmpNum = , ant = ;
for(int i = tmpStr.size()-; i >= ; -- i)
{
tmpNum += toNum(tmpStr[i])*ant;
if(tmpNum < || ant < )
return -;
ant *= radix;
}
return tmpNum;
}
long long minRadix(string tmpStr)
{
char tmpChar = ;
for(int i = ; i < tmpStr.size(); ++ i)
{
if(tmpStr[i] > tmpChar)
tmpChar = tmpStr[i];
}
return toNum(tmpChar) + ;
}
int main()
{
long long tag, radix, tmpNum, tmpTarget, lowRadix, highRadix;
string N1, N2;
cin >> N1 >> N2 >> tag >> radix;
//算出进制已经确定的数作为目标值
//并且 找出未确定进制的数的最小进制
if(tag == )
swap(N1, N2);
highRadix = tmpTarget = strRadixToNum(N1, radix);
lowRadix = max((long long) , minRadix(N2));
while(lowRadix <= highRadix)
{
long long midRadix = (lowRadix + highRadix)/;
long long tmpNum1 = strRadixToNum(N2, midRadix);
if(tmpNum1 >= tmpTarget ||tmpNum1 == -)
highRadix = midRadix - ;
else
lowRadix = midRadix + ;
}
if(strRadixToNum(N2, lowRadix) == tmpTarget)
cout << lowRadix;
else
cout << "Impossible";
return ;
}
A 1011 World Cup Betting (20 point(s))
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std;
int main()
{
double sum = 0.65, tmpW, tmpT, tmpL;
for(int i = ; i < ; ++ i)
{
cin >> tmpW >> tmpT >> tmpL;
if(tmpW > max(tmpT, tmpL))
{
cout << "W ";
sum *= tmpW;
}
else if(tmpT > max(tmpW, tmpL))
{
cout << "T ";
sum *= tmpT;
}
else
{
cout << "L ";
sum *= tmpL;;
}
}
printf("%.2f", (sum-)*);
return ;
}
A 1012 The Best Rank (25 point(s))
注意:1.排名的问题,相同成绩同一排名
2.最佳排名相同,按所给优先级
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <functional> using namespace std;
typedef struct NODE
{
int id, math, cCode, aver, english;
}node;
vector<int> cCodeVec, mathVec, engVec, averVec;
unordered_map<int, node> nodeMap;
unordered_map<int, int> nodeTableMap;
void getBestRank(int u)
{
int type = , rank, cnt;
char typeStr[]="ACME";
node tmpNode = nodeMap[u];
cnt = ;
for(auto it = averVec.begin(); it != averVec.end(); ++it, ++cnt)
if(*it == tmpNode.aver)
{
type = ; rank = cnt;break;
}
cnt = ;
for(auto it = cCodeVec.begin(); it != cCodeVec.end(); ++it, ++cnt)
if(*it == tmpNode.cCode && cnt < rank)
{
type = ; rank = cnt;break;
}
cnt = ;
for(auto it = mathVec.begin(); it != mathVec.end(); ++it, ++cnt)
if(*it == tmpNode.math && cnt < rank)
{
type = ; rank = cnt;break;
}
cnt = ;
for(auto it = engVec.begin(); it != engVec.end(); ++it, ++cnt)
if(*it == tmpNode.english && cnt < rank)
{
type = ; rank = cnt;break;
}
printf("%d %c\n", rank, typeStr[type]);
}
int main()
{
int N, M;
node tmpNode;
cin >> N >> M;
for(int i = ; i < N; ++i)
{
cin >> tmpNode.id >> tmpNode.cCode >> tmpNode.math >> tmpNode.english;
tmpNode.aver = (tmpNode.cCode + tmpNode.math + tmpNode.english+1.5)/;
cCodeVec.push_back(tmpNode.cCode); mathVec.push_back(tmpNode.math);
engVec.push_back(tmpNode.english); averVec.push_back(tmpNode.aver);
nodeMap[tmpNode.id] = tmpNode;nodeTableMap[tmpNode.id] = ;
}
sort(averVec.begin(), averVec.end(), greater<int>());
sort(cCodeVec.begin(), cCodeVec.end(), greater<int>());
sort(mathVec.begin(), mathVec.end(), greater<int>());
sort(engVec.begin(), engVec.end(), greater<int>());
for(int i = ; i < M; ++ i)
{
cin >> tmpNode.id;
if(nodeTableMap[tmpNode.id] > )
getBestRank(tmpNode.id);
else
cout << "N/A" << endl;
}
return ;
}
PAT A1009-1012的更多相关文章
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- PAT 乙级 1012
题目 题目地址:PAT 乙级 1012 思路 最后一个测试点怎么也过不了,问题在于A2的判断,不能单纯地以0作为判断条件:假设满足A2条件的只有两个数6和6,计算结果仍然是0,但是输出A2的值是0不是 ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- PAT乙级 1012. 数字分类 (20)
1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进 ...
- [C++]PAT乙级1012.数字分类 (20/20)
/* 1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和, ...
- PAT Basic 1012
1012 数字分类 (20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A1 = 能被 5 整除的数字中所有偶数的和: A2 = 将被 5 除后余 1 的数字 ...
- PAT 乙级 1012 数字分类 (20) C++版
1012. 数字分类 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一系列正整数,请按要求对数字进 ...
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- PAT乙级1012
1012 数字分类 (20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A1 = 能被 5 整除的数字中所有偶数的和: A2 = 将被 5 除后余 1 的 ...
- 【PAT】1012. 数字分类 (20)
1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...
随机推荐
- jmeter非GUI模式命令
一.如果没有.jtl文件,运行如下命令: jmeter -n -t baidu.jmx -l result.jtl 以非GUI形式运行Jmeter脚本jmeter -n -t baidu.jmx -l ...
- python三大神器===》生成器
1. 认识生成器 利用迭代器,我们可以在每次迭代获取数据(通过next()方法)时按照特定的规律进行生成.但是我们在实现一个迭代器时,关于当前迭代到的状态需要我们自己记录,进而才能根据当前状态生成下一 ...
- HDU - 6000 Wash(优先队列+贪心)
题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间. 分析: 1.优先队列处理出每件衣服最早的洗完时间. 2.优先队列 ...
- Windows平台整合SpringBoot+KAFKA__第3部分_代码部分(结束)
重要的地方说下,算是给自己提醒,也给阅读者凑合着看看吧: (1)序列化.反序列化: 注意看这个文章 https://www.jianshu.com/p/5da86afed228 很多网上的例子都是 推 ...
- 九、SAP中使用定义时间及使用sy-uzeit取当前时间
一.sy-uzeit为取当前时间函数,类型t为时间类型,代码如下: 二.输出结果如下:
- php观察者模式。
第一次写博客,大家多多关照!欢迎拍砖哦! 我也刚学设计模式,所以记录下来. <?php class person{ public $name; public $birthday; public ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 日期 & 时间
C++ 标准库没有提供所谓的日期类型.C++ 继承了 C 语言用于日期和时间操作的结构和函数.为了使用日期和时间相关的函数和结构,需要在 C++ 程序中引用 <ctime> 头文件. 有四 ...
- 学习EIGRP 笔记
CEFFIB(转发信息库,RIB现在运行了CEF,就称之为FIB)show ip cef detail EIGRP的基本组件:1.邻居发现机制2.可靠传输协议(RTP机制)3.DUAL算法4.多种网络 ...
- 04-String——课后作业1:字串加密
题目:请编写一个程序,加密或解密用户输入的英文字串要求设计思想.程序流程图.源代码.结果截图. 程序设计思想:首先由用户选择是加密还是解密,利用String类中的charAt函数依次取出字串中的字符, ...
- Python的递归深度问题
Python的递归深度问题 1.Python默认的递归深度是有限制的,当递归深度超过默认值的时候,就会引发RuntimeError.理论在997. 2.解决方法:最大递归层次的重新调整,解决方式是手工 ...