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(四)导入导出文件
1.导入json文件 2.单个文件夹导出,文件格式是 json文件 3.所有数据导出,文件格式是 json文件
- 接口测试工具postman(一)下载安装说明
Postman是Google开发的一款功能强大的网页调试与发送网页HTTP请求,并能运行测试用例的的Chrome插件. 主要功能包括: 1.模拟各种HTTP requests 从常用的 GET.POS ...
- CentOS环境配置Hadoop(一)
配置Linux开发环境(hadoop-2.6.4) 一.准备工具 VMware-workstation-10.0.1注册机 CentOS-6.5-x86_64-bin-DVD1 jdk-7u79-li ...
- kinit
su tf$ kinit -k -t /tmp/tf.keytab tf/admin@SINO.COM
- Gitlab自动触发Jenkins构建项目
Gitlab自动触发Jenkins构建项目 一.前提 Gitlab已安装配置好. Jenkins已安装Gitlab plugin. 二.配置jenkins中Job 1.勾选触发器下的gitlab触发器 ...
- POJ 1015 Jury Compromise (动态规划)
dp[i][j]代表选了i个人,D(J)-P(J)的值为j的状态下,D(J)+P(J)的最大和. #include <cstdio> #include <cstring> #i ...
- 预处理器&预处理变量&头文件保护&条件编译
[常见的预处理功能] #include 头文件保护符 条件编译 [预处理器] 编译之前执行的一段程序,可以部分地改变我们所写的程序 举个例子:当预处理器看到#include标记时就会用指定的头文件的内 ...
- ng2模板语法/内置指令速查表
https://www.angular.cn/docs/ts/latest/guide/cheatsheet.html
- Linux arm64的虚拟内存布局
原创翻译,转载请注明出处. 页表转换arm64在硬件体系结构上支持4级的每页大小为4K的页表转换,也支持3级的页大小64KB的页表转换.在linux arm64中,如果页的大小为4KB,使用3级页表转 ...
- Javascript中闭包常用场景
一.前言 有准备去看Javascript框架,所以对于Javascript和原型继承有必要去了解,这边小记一下闭包比较好的例子~ 二.正文 先来一下“闭包”的解释~ 一个拥有许多变量和绑定了这些变量的 ...