差分数列+字符串处理

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

通过对差分数列的不断求导,我们可以发现,对于任意多项式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. Form表单学习网站

    HTML表单 -- form标签 -- 与浏览者交互:http://www.dreamdu.com/xhtml/tag_form/

  2. ValueError: Attempted relative import in non-package

    执行:python deom/scripts/populate.py ValueError: Attempted relative import in non-package solve:python ...

  3. 【HTTP】Fiddler(一) - Fiddler简介和使用

    1.为什么是Fiddler? 抓包工具有很多,小到最常用的web调试工具firebug,达到通用的强大的抓包工具wireshark.为什么使用fiddler?原因如下: a.Firebug虽然可以抓包 ...

  4. Android ListView相关 fastScrollEnabled

    1.android:fastScrollEnabled="true" 当数据量比较多的时候,右侧会出现一个可以拉动的滚动条,这样可以很快的拉动,如图:

  5. eCos中的线程与同步

    http://blog.csdn.net/ooaven/article/details/6280018 先看一下eCos线程的创建.控制以及优先级的操作这三个方面的知识,主要是对它的实现方式及API做 ...

  6. mac中用命令行运行mysql

    1,安装mysql 在mysql的官方网站下载 mysql 5.5.23 http://www.mysql.com/downloads/mysql/,根据我的机器的配置情况选择了64bit版本. 2, ...

  7. NFC(6)NFC编程的几个重要类,NFC硬件启动android应用原理

    用于NFC编程的几个重要类 Tag NFC 标签 NfcAdapter Nfc 的适配类 NdefMessage 描述NDEF格式的信息 NdefRecord 描述NDEF信息的一个信息段,类似tab ...

  8. Android 签名(2)签名知识要点

    要点 1) 所有的应用程序都必须有数字证书,Android系统不会安装一个没有数字证书的应用程序 2) Android程序包使用的数字证书可以是自签名的,不需要一个权威的数字证书机构签名认证 3) 如 ...

  9. [转] android自动化测试之MonkeyRunner使用实例(三)

    一.使用CMD命令打开模拟器 运行monkeyrunner之前必须先运行相应的模拟器或连上设备,不然monkeyrunner无法连接设备. 1.1  用Elipse打开Android模拟器或在CMD中 ...

  10. poj 2524 Ubiquitous Religions (并查集)

    题目:http://poj.org/problem?id=2524 题意:问一个大学里学生的宗教,通过问一个学生可以知道另一个学生是不是跟他信仰同样的宗教.问学校里最多可能有多少个宗教. 也就是给定一 ...