Codeforces #475 div2
题目链接:http://codeforces.com/contest/964
A题 答案n/2+1;
B题 讨论三种情况
c>b
c==b
c<b
C题
数论,逆元+快速幂,但是我一直卡在了取模这个地方。迷之wa
AC代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<string.h>
4 #include<stdio.h>
5 #define ll long long
6 #define MOD 1000000009
7 using namespace std;
8 char s[100500];
9 ll quick_pow(ll a,ll b,ll n,ll x){
10 ll ans=1,base=a;
11 ll y=n-x;
12 while(y!=0){
13 if(y&1){
14 ans=(ans*base)%MOD;
15 }
16 base=(base*base)%MOD;
17 y>>=1;
18 }
19 base=b;
20 while(x!=0){
21 if(x&1){
22 ans=(ans*base)%MOD;
23 }
24 base=(base*base)%MOD;
25 x>>=1;
26 }
27 return ans%MOD;
28 }
29 ll qkm(ll a,ll y){
30 ll ans=1,base=a;
31 while(y!=0){
32 if(y&1){
33 ans=(ans*base)%MOD;
34 }
35 base=(base*base)%MOD;
36 y>>=1;
37 }
38 return ans%MOD;
39 }
40 int main(){
41 ll n,a,b,k;
42 cin>>n>>a>>b>>k;
43 scanf("%s",s);
44 ll ans=0;
45 /*for(ll i=0;i<k;i++){
46 if(s[i]=='+'){
47 ans=(ans+quick_pow(a,b,n,i))%MOD;
48 }else{
49 ans=(ans-quick_pow(a,b,n,i))%MOD;
50 }
51 }*/
52 for (ll i=0;i<k;i++)
53 {
54 if(s[i]=='+')
55 {
56 ans= (ans+qkm(a,n-i)*qkm(b,i)%MOD+MOD)%MOD;
57 }
58 if(s[i]=='-')
59 {
60 ans= (ans-qkm(a,n-i)*qkm(b,i)%MOD+MOD)%MOD;
61 }
62 }
63 ll cir=(n+1)/k;
64 //ll inva=qkm(a,MOD-2);
65 ll q=(qkm(b,k)*qkm(a,k*(MOD-2)))%MOD;
66 if(q!=1){
67 ans=ans*(qkm(q,cir)-1)%MOD*(qkm(q-1,MOD-2))%MOD; //这里,如果我先对后面两个取模就会wa,错在第7组测试数据,迷~
68 }else{
69 ans=(cir*ans)%MOD;
70 }
71 cout<<ans<<endl;
72 return 0;
73 }
Codeforces #475 div2的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- [codeforces round#475 div2 ][C Alternating Sum ]
http://codeforces.com/contest/964/problem/C 题目大意:给出一个等比序列求和并且mod 1e9+9. 题目分析:等比数列的前n项和公式通过等公比错位相减法可以 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- Google Hacking语法总结
Google Hacking语法总结 Google Hacking是利用谷歌搜索的强大,来在浩瀚的互联网中搜索到我们需要的信息.轻量级的搜索可以搜素出一些遗留后门,不想被发现的后台入口,中量级的搜索出 ...
- 对称加密 vs 非对称加密
计算机网络在给我们带来便利的同时,也存在很多安全隐患,比如信息伪造,病毒入侵,端点监听,SQL 注入等,给我们日常生活造成很严重的影响. 那么这篇文章我就跟大家聊聊常见的网络安全隐患,只作为科普,不能 ...
- 5-MySQL列定义
1.列定义 说明:在MySQL中,列定义(Column Definition)是用于定义数据库表中每一列的结构的语句.它指定了列的名称.数据类型.长度.约束以及其他属性. 2.主键和自增 主键:PRI ...
- 2023版:深度比较几种.NET Excel导出库的性能差异
引言 背景和目的 本文介绍了几个常用的电子表格处理库,包括EPPlus.NPOI.Aspose.Cells和DocumentFormat.OpenXml,我们将对这些库进行性能测评,以便为开发人员提供 ...
- gitbook在线记事本
https://app.gitbook.com/ About this template: An Internal Wiki to lay out everything anyone needs to ...
- Android历史版本
目录 [隐藏] 1 测试版 2 版本列表 2.1 Android 1.0 2.2 Android 1.1 2.3 Android 1.5 Cupcake 2.4 Android 1.6 Donut ...
- Java多线程笔记全过程(一)
一.多线程最基础的基本概念 一个程序最少需要一个进程,而一个进程最少需要一个线程. 我们常说的高并发,也并不全是线程级别的并发,在很多开发语言中,比如PHP,很常见的都是进程级别的并发.但是在Java ...
- 【对象存储】Minio本地运行和 golang客户端基本操作
运行环境 OS和Golang版本: go version go1.21.0 darwin/arm64 安装 源码安装 下载最新版本的源码,地址https://github.com/minio/mini ...
- sql删除进程
使用一下语句杀掉进程 USE master go DECLARE @dbname VARCHAR(200) SET @dbname = 'xxxx' --要关闭进程的数据库名 DECLARE @sql ...
- 容器中sh脚本明明存在,为何会报"no such file or directory"的错误?
小伙伴碰到一起奇怪的事故,从gitlab上拉取的docker镜像项目,在本地开发机上进行docker build后,启动容器会报错如下: exec /app/run.sh : no such file ...