差分数列+字符串处理

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

通过对差分数列的不断求导,我们可以发现,对于任意多项式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. java对象数组

    问题描述:     java 对象数组的使用 问题解决: 数组元素可以是任何类型(只要所有元素具有相同的类型) 数组元素可以是基本数据类型 数组元素也可以是类对象,称这样的数组为对象数组.在这种情况下 ...

  2. Ubuntu的挂起和休眠

    Ubuntu的挂起和休眠 之前一直没关注过这方面的信息,因为以前只是在台式机上面用Ubuntu,笔记本一直都是Windows.随着Windows越来越傻冒,最近决定将常用系统转为Ubuntu,才注意到 ...

  3. PAT-乙级-1028. 人口普查(20)

    1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...

  4. 【转】Java自动装箱、拆箱、缓冲池

    JDK5以后 Integer a = 3;              这是自动装箱int     i = new Integer(2); 这是自动拆箱就是基本类型和其对应的包装类型在需要的时候可以互相 ...

  5. [Unity菜鸟] Unity读XML

    1. 在Unity中调试可行,发布成exe可行,发布成web不行 Application.dataPath 在Unity中调试是在“..Assets”文件夹下, 发布成exe文件是在“..yourNa ...

  6. Android四大基本组件

    Android四大基本组件分别是 Activity:整个应用程序的门面,负责与用户进行交互. Service:承担大部分工作. Content Provider内容提供者:负责对外提供数据,并允许需要 ...

  7. Oracle Exception 处理

    1.问题来源Oracle中可以用dbms_output.put_line来打印提示信息,但是很容易缓冲区就溢出了.可以用DBMS_OUTPUT.ENABLE(1000000);来设置缓冲区的大小.但是 ...

  8. uva 11817 - Tunnelling the Earth

    题意:从地球上的一个点到另一个点,求两点的球面距离和直线距离之差.假定地球是正球体,半径为6371009米. #include<iostream> #include<cmath> ...

  9. 2.1 linux中uboot移植

    -- --------------------------------------------------------------------------------------- (一)友善之臂介绍 ...

  10. cookie分析

    浏览器cookie分析 简单点说就是数据存储,通过JavaScript将要保存的数据保存在客户端浏览器,下次打开网页时调用保存的cookie.浏览器中cookie保存的形式:user=aa; pwd= ...