A 1015 Reversible Primes

  看清题意即可。给的数是十进制的,需要先判断是不是素数,然后按照给定进制转化成字符串后进行翻转,最后再转化为十进制并判断是否为素数。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std; int N, D;
char numStr[];
bool isPrime(int tmpNum)
{
if(tmpNum < )
return false;
int maxNum = sqrt(1.0*tmpNum);
for(int i = ; i <= maxNum; ++ i)
if(tmpNum % i == )
return false;
return true;
}
int strToNum()
{
int len = strlen(numStr), tmpNum = ;
for(int i = ; i < len; ++ i)
{
tmpNum = tmpNum*D + numStr[i]-'';
}
return tmpNum;
}
int main()
{
int tmpNum;
while(scanf("%d%d", &N, &D) != EOF && N >= )
{
if(!isPrime(N))
{
cout << "No" << endl;
continue;
}
for(int i = ; N > ; ++ i)
{
numStr[i] = N % D + '';
N /= D;
numStr[i+] = '\0';
}
tmpNum = strToNum();
if(!isPrime(tmpNum))
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return ;
}

A 1016 1016 Phone Bills

 因为存在无效的记录,所以需要将他们先进行配对。处理方法是:按照名字和时间进行排序,然后筛选出所需要的记录再进行下一步处理。

 超时问题:每一个有效时间段的话费计算需要尽量减少计算量。

以下是柳婼精简的代码:

 #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
struct node {
string name;
int status, month, time, day, hour, minute;
};
bool cmp(node a, node b) {
return a.name != b.name ? a.name < b.name : a.time < b.time;
}
double billFromZero(node call, int *rate) {
double total = rate[call.hour] * call.minute + rate[] * * call.day;
for (int i = ; i < call.hour; i++)
total += rate[i] * ;
return total / 100.0;
}
int main() {
int rate[] = {}, n;
for (int i = ; i < ; i++) {
scanf("%d", &rate[i]);
rate[] += rate[i];
}
scanf("%d", &n);
vector<node> data(n);
for (int i = ; i < n; i++) {
cin >> data[i].name;
scanf("%d:%d:%d:%d", &data[i].month, &data[i].day, &data[i].hour, &data[i].minute);
string temp;
cin >> temp;
data[i].status = (temp == "on-line") ? : ;
data[i].time = data[i].day * * + data[i].hour * + data[i].minute;
}
sort(data.begin(), data.end(), cmp);
map<string, vector<node> > custom;
for (int i = ; i < n; i++) {
if (data[i].name == data[i - ].name && data[i - ].status == && data[i].status == ) {
custom[data[i - ].name].push_back(data[i - ]);
custom[data[i].name].push_back(data[i]);
}
}
for (auto it : custom) {
vector<node> temp = it.second;
cout << it.first;
printf(" %02d\n", temp[].month);
double total = 0.0;
for (int i = ; i < temp.size(); i += ) {
double t = billFromZero(temp[i], rate) - billFromZero(temp[i - ], rate);
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", temp[i - ].day, temp[i - ].hour, temp[i - ].minute, temp[i].day, temp[i].hour, temp[i].minute, temp[i].time - temp[i - ].time, t);
total += t;
}
printf("Total amount: $%.2f\n", total);
}
return ;
}

PAT A1015-1016的更多相关文章

  1. PAT甲级1016. Phone Bills

    PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...

  2. PAT——乙级1016

    乙级PAT的1016 乙级的题相对比较简单,我也是主要联系写代码的格式,而不是联系算法. 1016 部分A+B (15 point(s)) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由  ...

  3. PAT A 1016. Phone Bills (25)【模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...

  4. PAT乙级 1016. 部分A+B (15) C语言实现

    1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部 ...

  5. PAT Basic 1016

    1016 部分A+B (15 分) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 A ...

  6. PAT乙级 1016. 部分A+B (15)

    题目传送:https://www.patest.cn/contests/pat-b-practise/1016 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A ...

  7. PAT乙级1016

    1016 部分A+B (15 分)   正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 ...

  8. 【PAT】1016 部分A+B(15 分)

    1016 部分A+B(15 分) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 A  ...

  9. pat甲级1016

    1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following ...

  10. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

随机推荐

  1. 蓝桥杯 2n皇后问题

    题意: 问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行.同一列或同一条对角线上,任意的两个白皇后都不在同一行.同一 ...

  2. liunx mysql 5.7 二进制安装

    liunx 5.6版本 本人安装次数不下20次,基本上按照正常的操作流程不会出现什么问题,一切顺利. 今天开发新项目需要按照mysql 5.7 版本.mysql 5.7版本和mysql 5.6版本变化 ...

  3. angular.js开发 将多页面开发成单页面

    用angulara.js做单页面开发时,由于不能跨页面取数据,又需要传参,可以采用:$scope.step=0/1来解决这个问题,设置初始值为想要的页面即可.

  4. 使用delphi TThread类创建线程备忘录

    备忘,不常用经常忘了细节 TMyThread = class(TThread) private { Private declarations } protected procedure Execute ...

  5. 吴裕雄--天生自然java开发常用类库学习笔记:NumberFormat

    import java.text.* ; public class NumberFormatDemo01{ public static void main(String args[]){ Number ...

  6. 《ES6标准入门》(阮一峰)--3.变量的解构赋值

    1.数组的解构赋值 基本用法 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; l ...

  7. P1085 PAT单位排行

    转跳点:

  8. P1010 一元多项式求导

    1010 一元多项式求导 (转跳点:

  9. UVA - 679 Dropping Balls(二叉树的编号)

    题意:二叉树按层次遍历从1开始标号,所有叶子结点深度相同,每个结点开关初始状态皆为关闭,小球从根结点开始下落(小球落在结点开关上会使结点开关状态改变),若结点开关关闭,则小球往左走,否则往右走,给定二 ...

  10. Oracle的操作经验

    采用Oracle进行sql语句 建表并设置主键,主键自增,某一字段唯一性约束等 <---如果表存在则删除---> declare num number; begin select coun ...