UVALive 7327【模拟】
题意:
每次方案一个或多个子序列;
每个子序列要整除m
认为分割不同,子序列边界的不同就是不同;
1246有4个
1246
12 46
124 6
12 4 6
思路:
先从整体考虑,因为取膜适用于加法,所以一个数拆分成两个数%m==0就代表这个数%m一定=0;
再考虑把原串划分成两段,当且仅当某个前缀组成的数能被m整除时,原串才能被分成两段.
划成多段同理.
求出有多少地方能被切割,结果就是 2^(res-1). 就是相当于枚举每个位置切割or不切割结果.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
const int N=3e5+10;
const LL mod=1e9+7;
char s[N];
LL cal(LL g,LL x)
{
LL ans=1;
while(g)
{
if(g%2) ans=(ans*x)%mod;
x=(x*x)%mod;
g>>=1;
}
return ans;
}
int main()
{
LL n;
LL m;
while(~scanf("%lld%lld",&n,&m))
{
LL res=0;
LL temp=0;
scanf("%s",s);
for(LL i=0;i<n;i++)
{
temp=(temp*10LL+s[i]-'0')%m;
if(!temp)
res++;
}
if(temp)
{
puts("0");
continue;
}
printf("%lld\n",cal(res-1,2));
}
return 0;
}
UVALive 7327【模拟】的更多相关文章
- UVALive 7327 Digit Division (模拟)
Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...
- 模拟/字符串处理 UVALive 6833 Miscalculatio
题目传送门 /* 模拟/字符串处理:主要是对*的处理,先把乘的预处理后再用加法,比如说是:1+2*3+4 = 1+..6+4 = 11 */ #include <cstdio> #incl ...
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- UVALive 6093 Emergency Room --优先队列实现的模拟
题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每 ...
- UVALive 6257 Chemist's vows --一道题的三种解法(模拟,DFS,DP)
题意:给一个元素周期表的元素符号(114种),再给一个串,问这个串能否有这些元素符号组成(全为小写). 解法1:动态规划 定义:dp[i]表示到 i 这个字符为止,能否有元素周期表里的符号构成. 则有 ...
- UVALive 5880 Vigenère Cipher Encryption (模拟)
Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26628 Description http://7xjob4.c ...
- UVALive 5888 Stack Machine Executor (栈+模拟)
Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26636 Description http://7xjob4.c ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- UVALive 3486/zoj 2615 Cells(栈模拟dfs)
这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...
随机推荐
- CentOS 安装和配置 Mantis
Mantis是一个基于PHP技术的轻量级的开源缺陷跟踪系统,以Web操作的形式提供项目管理及缺陷跟踪服务.在功能上.实用性上足以满足中小型项目的管理及跟踪.更重要的是其开源,不需要负担任何费用. 1. ...
- Time To First Byte (TTFB) 第一字节时间 页面加载时间
Time to first byte - Wikipedia https://en.wikipedia.org/wiki/Time_to_first_byte Time to first byte ( ...
- Avro schemas are defined with JSON . This facilitates implementation in languages that already have JSON libraries.
https://avro.apache.org/docs/current/ Introduction Apache Avro™ is a data serialization system. Avro ...
- pdf文件的作成
Dim Report As New crProgressList Report.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.P ...
- java之EJB
EjB,只是一个服务端运行组件,公开接口供客户端以C/S方式调用而已. 最直白,最本质的解释,可参见: http://blog.csdn.net/jojo52013145/article/detail ...
- UVA10129 Play on Words —— 欧拉回路
题目链接:https://vjudge.net/problem/UVA-10129 代码如下: // UVa10129 Play on Words // Rujia Liu // 题意:输入n个单词, ...
- 人生苦短之Python的urllib urllib2 requests
在Python中涉及到URL请求相关的操作涉及到模块有urllib,urllib2,requests,其中urllib和urllib2是Python自带的HTTP访问标准库,requsets是第三方库 ...
- suishou
sageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn you ...
- 加快你的JavaScript加载时间
发现可以提速的内容 你必须首先发现你的什么图片和HTML加载缓慢了你的脚本速度,下面提供了方法: 1. Firefox web-developer toolbar 2. Firebug Plugi ...
- 【C】由printf("%d\t%d\t%d\n",a,a+=(a++),a);引起的思考
#include<stdio.h> int main() { ,a1=; ,b1=; printf("(1)后自加:\n"); printf("a+=(a++ ...