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的数字按给出顺序进行交错求和,即计算 ...
随机推荐
- FC 与 FB 与 OB 的区别,时间标记冲突与一致性检查 有详细的步骤
关键字1 组织块的程序是由用户自己编写. 关键字2 时间标记冲突与一致性检查 有详细的步骤. 关键字3 FC 与 FB 与 OB 的区别? (一)功能 功能块 区别 ? FB 和FC均为 用户编写 ...
- C++ Socket WSAENOBUFS WSAoverlapped
WSARecv的时候,投递的接收缓冲区的大小设置为0. 然后手动调用非阻塞recv从缓冲区接受数据,直到WSAEWOULDBLOCK,不然会有很多的buffer被锁住,当客户端的数量达到一定数目时,就 ...
- 文本编辑器vim/vi——命令模式
一个完整的指令的标准格式: Linux通用的格式——#指令主体(空格) [选项](空格) [操作对象] 一个指令可以包含多个选项,操作对象也可以是多个. vim指令: 指令:vim (vim是一款 ...
- No 'Access-Control-Allow-Origin' header is present on the requested resource——Web Api跨域问题
最近使用C#写了一个简单的web api项目,在使用项目中的.cshtml文档测试的时候没有任何问题,但是在外部HBuilder上面编写.html通过Ajax调用web api路径时报错: No 'A ...
- 联系我们地图坐标展示js
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6d88 ...
- Codeforces 460C 二分结果+线段树维护
发现最近碰到好多次二分结果的题目,上次多校也是,被我很机智的快速过了,这个思想确实非常不错.在正面求比较难处理的时候,二分结果再判断是否有效往往柳暗花明. 这个题目给定n个数字的序列,可以操作m次,每 ...
- c\c++ 中字符串分割,并且转换为整形数据
在项目开发中,经常使用到字符串分割, 并且将其转换为整形(比如IP的分割获取,MAC地址的分割获取等),代码如下: #ifndef _UNICODE void StrToIntData( char * ...
- 19 01 15 js 尺寸相关 滚动事件
尺寸相关.滚动事件 1.获取和设置元素的尺寸 width().height() 获取元素width和height innerWidth().innerHeight() 包括padding的width和 ...
- mailx发送邮件
cent6.5自带mailx 这是个第三方的邮件发送 比如用自己的126给其他账户发邮件 cent6.5还自带了postfix 可以停掉 sendmail(cent5才自带6是postfix)也 ...
- org.apache.jasper.JasperException: /WEB-INFO/jsp/product/edit.jsp(168,45)
PWC6038:"${empty data.code?'001':fn:substring(data.code,0,8)}" contains invalid expression ...