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的数字按给出顺序进行交错求和,即计算 ...
随机推荐
- 吴裕雄--天生自然java开发常用类库学习笔记:System类
public class SystemDemo01{ public static void main(String args[]){ long startTime = System.currentTi ...
- JavaScript动态实现div窗口弹出&消失功能
先积累一个JavaScript动态实现div窗口弹出&消失功能 首先是index.jsp代码 <html> <head> <link rel="styl ...
- 记录:JAVA抽象类、接口、多态
JAVA抽象类.接口.多态 1. 多态 定义 多态是同一个行为具有多个不同表现形式或形态的能力.(多态就是同一个接口,使用不同的实例而执行不同操作) 如何实现多态 继承和接口 父类和接口类型的变量赋值 ...
- 二、【重点】环境安装:通过淘宝 cnpm 快速安装使用 React,生成项目,运行项目、安装项目
1.cnpm代替npm 如果你的系统还不支持 Node.js 及 NPM 可以参考我们的 Node.js 教程. 我们建议在 React 中使用 CommonJS 模块系统,比如 browserify ...
- Elasticsearch 过滤
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- ORM——Mybatis
引言 ORM 是 blablabla…… Mybatis知识点
- CCCC L3-015. 球队“食物链”(dfs+剪枝)
题意: 某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席突发奇想,希望从中找出一条包含所有球队的 ...
- 洛谷 P2516 [HAOI2010]最长公共子序列
题目传送门 解题思路: 第一问要求最长公共子序列,直接套模板就好了. 第二问要求数量,ans[i][j]表示第一个字符串前i个字符,第二个字符串前j个字符的最长公共子序列的数量 如果f[i][j]是由 ...
- 2.11 DataBinding 简单使用
DataBindIng 在我理解看来类似于其他语言当中的全局变量,只修改一处就可全部修改 添加位置和代码如下: 打开DataBinding 开关: dataBinding { enabled true ...
- Standard Aras Dialogs
In a another blog post, we covered how to open dialogs within Aras Innovator using custom forms and ...