HDU2441 ACM(Array Complicated Manipulation)
ACM(Array Complicated Manipulation)
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 513 Accepted Submission(s): 104
The operation is to choose a minimum number from the array which is never been chosen, then change the status of its multiples excluding itself, i.e remove the multiples of the chosen number if they are in the array , otherwise add it to the array.keep the order after change.
For instance, the first step, choose number 2, change the status of 4, 6, 8, 10... They are all removed from the array. The second step, choose 3, change the status of 6, 9, 12, 15...
Pay attention: 9 and 15 are removed from the array while 6 and 12 are added to the array.
The number n never has a prime factor greater than 13000000, but n may be extremely large.
/*
ID: LinKArftc
PROG: 2441.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; #define DLEN 4
#define MAXN 9999
const int maxn = ;
int num[maxn];
int prime[maxn];
int cnt;
char str[]; void init() {
cnt = ;
memset(num, -, sizeof(num));
for (int i = ; i <= (maxn >> ); i ++) {
for (int j = (i << ); j <= maxn; j += i) num[j] = ;
}
for (int i = ; i <= maxn; i ++) {
if (num[i]) prime[cnt ++] = i;
}
} class BigNum {
private:
int a[];
int len;
public:
BigNum() { len = ; memset(a, , sizeof(a)); }
BigNum(const char*);
BigNum(const BigNum &);
BigNum &operator=(const BigNum &);
BigNum operator+(const BigNum &) const;
BigNum operator-(const BigNum &) const;
BigNum operator*(const BigNum &) const;
BigNum operator/(const int &) const;
int operator%(const int &) const;
void print();
}; BigNum::BigNum(const char*s) {
int t, k, index, L, i;
memset(a, , sizeof(a));
L = strlen(s);
len = L / DLEN;
if (L % DLEN) len ++;
index = ;
for (i = L - ; i >= ; i -= DLEN) {
t = ;
k = i - DLEN + ;
if (k < ) k = ;
for (int j = k; j <= i; j ++) t = t * + s[j] - '';
a[index ++] = t;
}
} BigNum::BigNum(const BigNum &T):len(T.len) {
int i;
memset(a, , sizeof(a));
for (i = ; i < len; i ++) a[i] = T.a[i];
} BigNum & BigNum::operator=(const BigNum &n) {
int i;
len = n.len;
memset(a, , sizeof(a));
for (i = ; i < len; i ++) a[i] = n.a[i];
return *this;
} BigNum BigNum::operator/(const int &b) const {
BigNum ret;
int i, down = ;
for (int i = len - ; i >= ; i --) {
ret.a[i] = (a[i] + down * (MAXN + )) / b;
down = a[i] + down * (MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while (ret.a[ret.len - ] == && ret.len > ) ret.len --;
return ret;
} int BigNum::operator%(const int &b) const {
int i, d = ;
for (int i = len - ; i >= ; i --) d = ((d * (MAXN + )) % b + a[i]) % b;
return d;
} void BigNum::print() {
int i;
printf("%d", a[len-]);
for (int i = len - ; i >= ; i --) printf("%04d", a[i]);
printf("\n");
} int main() {
init();
while (~scanf("%s", str)) {
if (str[] == '') break;
if (strlen(str) == && str[] == '') {
printf("no\n");
continue;
}
BigNum n = BigNum(str);
int count;
for (int i = ; i < cnt; i ++) {
count = ;
BigNum tmp = n;
while (tmp % prime[i] == ) {
count ++;
tmp = tmp / prime[i];
if (count >= ) break;
}
if (count >= ) break;
}
if (count >= ) printf("no\n");
else printf("yes\n");
} return ;
}
HDU2441 ACM(Array Complicated Manipulation)的更多相关文章
- CSc 352 (Spring 2019): Assignment
CSc 352 (Spring 2019): Assignment 11Due Date: 11:59PM Wed, May 1The purpose of this assignment is to ...
- leetcode——169 Majority Element(数组中出现次数过半的元素)
Given an array of size n, find the majority element. The majority element is the element that appear ...
- Java Algorithm Problems
Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
题目描述 Given an array A with length n a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...
- 2017 ACM/ICPC Asia Regional Shenyang Online array array array
2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...
- ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...
- AndyQsmart ACM学习历程——ZOJ3872 Beauty of Array(递推)
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
- [Python Cookbook] Numpy Array Manipulation
1. Reshape: The np.reshape() method will give a new shape to an array without changing its data. Not ...
- “玲珑杯”ACM比赛 Round #4 E -- array DP
http://www.ifrog.cc/acm/problem/1050?contest=1006&no=4 DP[val]表示以val这个值结尾的等差数列有多少个 DP[val] += DP ...
随机推荐
- 接口测试工具postman(一)下载安装说明
Postman是Google开发的一款功能强大的网页调试与发送网页HTTP请求,并能运行测试用例的的Chrome插件. 主要功能包括: 1.模拟各种HTTP requests 从常用的 GET.POS ...
- Python面试315题
感谢老男孩的武沛齐老师辛苦整理和分享,本文是转自他的博客. 第一部分 Python基础篇(80题) 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C# ...
- 剑指offer-二叉树的镜像18
题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...
- kickstart技术安装操作系统
kickstart是RedHat公司开源的软件,所以对CentOS兼容性最好. 原理:我们将手动安装的所有的详细步骤记录到一个文件中,然后kickstart通过读取这个文件就可以实现自动化安装系统. ...
- Mapper的方式总结
Mapper的方式总结: <mappers> <!-- 通过package元素将会把指定包下面的所有Mapper接口进行注册 --> <package name=&quo ...
- POJ 3860 Fruit Weights(数学+最长路径 or 最短路径)
Description Have you ever thought about comparing the weight of fruits? That’s what you should do in ...
- UnrealEngine4入门(一) 新建一个c++项目
epic games宣布ue4免费使用(游戏发布之后,每个季度大于3000美元则收取收益的5%)之后,吸引了大批看好VR和AR前景的游戏开发者.不过国内(中文)ue4教程和资料太少,而且一大部分资料都 ...
- 3GPP规范命名规则解读
http://blog.sina.com.cn/s/blog_6b10255301012co6.html 学习了解电信技术知识的一个很好的手段是阅读3GPP的规范.但是3GPP有大量的规范,我们可能经 ...
- systemtap如何写C函数 捎带着看看ret kprobe怎么用
在systemstap中自定义函数 Embedded C can be the body of a script function. Instead enclosing the function bo ...
- 02.Java面向对象问题
目录介绍 2.0.0.1 重载和重写的区别?重载和重写绑定机制有何区别?父类的静态方法能否被子类重写? 2.0.0.2 封装.继承.多态分别是什么? 2.0.0.3 接口和抽象类的区别是什么?接口的意 ...