差分数列+字符串处理

题意:是让你判断一个整系数多项式的值是否一直都能被一个所给的正整数所整除。

通过对差分数列的不断求导,我们可以发现,对于任意多项式P,我们只需要判断n从1到k+1是否满足就行了,其中,k为多项式P中的最高次数。

可以先了解一下差分数列。

 #include <iostream>
#include <cstdio>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<cassert>
using namespace std;
struct Polynomial
{
vector<int >a,p;
void parse_polynomial(string str)
{
int len=str.size(),i=;
while(i<len)
{
int sign=;
if(str[i]=='+')
i++;
if(str[i]=='-')
{
i++;
sign=-;
}
int v=;
while(i<len&&isdigit(str[i]))
v=v*+str[i++]-'';
if(i==len)
{
a.push_back(v);
p.push_back();
}
else
{
assert(str[i] == 'n');
if(v==)
v=;
v*=sign;
if(str[++i]=='^')
{
a.push_back(v);
v=;
i++;
while(i<len&&isdigit(str[i]))
v=v*+str[i++]-'';
p.push_back(v);
}
else
{
a.push_back(v);
p.push_back();
}
}
}
}
int mod(int x,int MOD)
{
int n=a.size();
int ans=;
for(int i=; i<n; i++)
{
int m=a[i];
for(int j=; j<p[i]; j++)
{
m=(long long)m*x%MOD;
}
ans=((long long)ans + m) % MOD;
}
return ans;
}
}; bool check(string str)
{
int p=str.find('/');
Polynomial poly;
poly.parse_polynomial(str.substr(, p-));
int D = atoi(str.substr(p+).c_str());
for(int i=; i<=poly.p[]+;i++)
{
if(poly.mod(i,D))
return false;
}
return true;
} int main()
{
int cas=;
string str;
while(cin>>str)
{
if(str[]=='.')
break;
printf("Case %d: ", cas++);
if(check(str))
printf("Always an integer\n");
else
printf("Not always an integer\n");
}
return ;
}

uvalive 4119 Always an Interger的更多相关文章

  1. UVALive 4119 Always an integer (差分数列,模拟)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Always an integer Time Limit:3000MS     M ...

  2. Always an integer UVALive - 4119

    题目很简单,就是求表达式(P/D)的结果是不是整数.其中P是一个整系数的多项式,D是一个正整数. 把1-k(最高次)+1都试一次就好了.结论可以总结归纳得到.(k取 0, 1, 2 .... 的情况推 ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. Interger 与 int

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. ExtJS4.2学习(18)时间控件(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-12-22/190.html 感谢“束洋洋 ”的付出. 前言 ...

  2. [转载]EasyUI Pagination 分页的两种做法

    EasyUI 的 datagrid 支持服务器端分页,但是官方的资料比较少,以下总结了两种 datagrid 的服务器端分页机制,可根据情况具体使用. 一:使用 datagrid 默认机制 后台: p ...

  3. spoj 346

    当一个数大于等于12  那分别处以2, 3, 4之后的和一定大于本身    但是直接递归会超时    然后发现有人用map存了   膜拜..... #include <cstdio> #i ...

  4. import,reload,__import__在python中的区别

    import,reload,__import__在python中的区别 http://blog.csdn.net/five3/article/details/7762870 import作用:导入/引 ...

  5. oracle 增加字段

    之前很多表增加很多相同的字段,一个一个添加太慢烦了,于是用了以下的方法alter table t_xmlc_batch_out_head_bak add ( SENDRECEIVEFLAG ) , S ...

  6. altium designer 13 学习之添加汉字

    在altium desginer中如果你是想添加英文还是比较方便的,基本直接就可以输入了,但是添加中文就不是那么简单了,下面不介绍下如何在altium designer中快速的添加自己想要的中文 工具 ...

  7. 一个php类 Autoloader

    php autoloader: This is a class for PHP that keeps the user from having to manually include classes ...

  8. ubuntu装机

    备份: .bashrc profile .vimrc exports defults/ 各种workspace中的源码 goagent/ 重转后安装: apt-get install openjdk- ...

  9. Exynos 4412的启动过程分析[2]

    做实验时我们是把 bin 文件烧入SD卡,比如前面做的汇编流水灯实验. 问:是谁把这些指令从 SD 卡读出来执行? 答:是固化在芯片内部ROM上的代码---它被称为iROM ,iROM是厂家事先烧写在 ...

  10. php.ini – 配置文件详解

    详见: https://my.oschina.net/miaowang/blog/299546 这个文件必须命名为''php.ini''并放置在httpd.conf中的PHPIniDir指令指定的目录 ...