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. 记-ItextPDF+freemaker 生成PDF文件---导致服务宕机

    摘要:已经上线的项目,出现服务挂掉的情况. 介绍:该服务是专门做打印的,业务需求是生成PDF文件进行页面预览,主要是使用ItextPDF+freemaker技术生成一系列PDF文件,其中生成流程有:解 ...

  2. Codeforces 1294D - MEX maximizing

    思维,真的很巧妙啊,看了以下博客 https://www.cnblogs.com/stelayuri/p/12230033.html

  3. XV6源代码阅读-虚拟内存管理

    Exercise1 源代码阅读 1.内存管理部分: kalloc.c vm.c 以及相关其他文件代码 kalloc.c:char * kalloc(void)负责在需要的时候为用户空间.内核栈.页表页 ...

  4. 解题报告:luogu P2299

    题目链接:P2299 Mzc和体委的争夺战 单源最短路板子题吗,体面晦涩难懂(语文不好),以为是有向图,只有\(30pts\),其实是无向的,我使用了刚学来的\(SPFA\),通过了此题: \(Cod ...

  5. 剑指offer第12题打印从1到n位数以及大整数加法乘法

       字符和数字加减就是字符的ASCII码和数字直接加减. 方法一: 1)在字符串操作中给一个整形数字加(字符0)就是把它转化为字符,当然给一个字符减去(字符0)就可以把它转化为数字了:如果确实是最后 ...

  6. 010-PHP输出数组中第某个元素

    <?php $monthName = array(1 => "January", "February", "March",//初 ...

  7. SpringBoot-配置Java方式

    SpringBoot中使用Java方式配置步骤如下: 在类上加入@Configuration注解,代表作为配置类 在该类方法上加入@Bean注解,代表将方法返回的Bean加入Spring容器 在该类中 ...

  8. 十八、React react-router4.x中:实现路由模块化、以及嵌套路由父子组件传值

    一.路由模块化(用字典定义路由,然后循环出来) 1.官方文档参考 [官方文档]https://reacttraining.com/react-router/web/guides/quick-start ...

  9. 从0开始自己配置一个vps虚拟服务器(1)

    我前几年买的虚拟机都被我荒废了,我已经配置过很多遍了,但是从来没有真的用过.因为我前几个月之前又新买了一个便宜的服务,准备写新的东西.供应商pacificrack,真的很烂,一直断,控制面板还打不开, ...

  10. 2020/2/22 74cms3.5.1 代码审计

    0x00 网站结构 简单试了一下.每一个模块还是比较清楚的,分别对应网站的一个模块.还有一些没有权限访问 0x01 通读代码 先看入口文件,index.php 开头先对网站是否安装做了判断 然后就是判 ...