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 ...
随机推荐
- 【SpringCloud】第一篇: 服务的注册与发现(Eureka)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- 3、shader深度测试(Cull、ZWrite 、ZTest )
剔除和深度测试是渲染法线中的一个流程 Cull:默认情况下,Unity中给的所有Shader都是单面的,它都把反面的渲染给关闭掉了,如果你在开发的过程中需要使用到双面,只要把cull关闭(off)即可 ...
- 简历编写技巧-java开发工程师简历实战
看到一遍简历编写的文章 想到也快找工作了 早晚能够用上 现在摘录如下 640?wx_fmt=jpeg 工欲善其事,必先利其器,这是自古以来的道理.所以如果想找到一份好的工作,一定要先整理一份好的简历. ...
- hibernate和mybatis的之CRUD封装差别
hibernate和mybatis的之CRUD封装差别 以下讲的是基于MVC三层架构. 由于设计架构的差别,hibernate在实际编程中可以把基础的CRUD封装,比如BaseDao类.其它类只要去继 ...
- POJ 2186 Popular Cows(强联通+缩点)
Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...
- winform 外部组件发生异常
问题描述.先前程序运行可以正常,但是突然这次调试就弹出此异常: 解决方法:1.本次调试是不是重新生成解决方案了?应该是因为之前的解决方案删了,把引用的dll(包含此dll关联的dll)自动删掉: 2. ...
- 《Hadoop基础教程》之初识Hadoop(转载)
转载自博主:上善若水任方圆http://blessht.iteye.com/blog/2095675 Hadoop一直是我想学习的技术,正巧最近项目组要做电子商城,我就开始研究Hadoop,虽然最后鉴 ...
- linux基本操作1
ctrl + alt + T 打开命令行 -根目录下home中为用户建的文件夹 cd 加目录名称转到当前目录 .当前目录..上级目录 ls 当前目录下的文件ls -l 显示当前目录下文件的权限 mkd ...
- springmvc项目搭建四-基于前端框架完善页面的数据显示
上一篇把前端框架先放上去了,现在开始前后端进行交互,对数据进行显示. 效果如图所示...中间经历了数据显示不上去的问题,是对于spring的注解了解不够,问题及其解决可以参照上一篇问题处理... 目前 ...
- java第七笔记