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; ...
随机推荐
- QA|不同模块之间的引用(导入问题)问题;|Pycharm
结构如图,在xxu的test.py中想要导入t2包中的sayhello和word两个方法 注意:首先需要打开xxu和t2的上层目录,因为解释器是从打开的那个文件开始查找的,所以这里应该打开B01_01 ...
- iOS开发过程中的内存监控
- HTML/网站一键打包APK工具(html网页打包安卓APP应用)
HTML一键打包APK工具使用说明 工具简介 HMTL一键打包APK工具可以把本地HTML项目或者网站打包为一个安卓应用APK文件,无需编写任何代码,也无需配置安卓开发环境,支持在最新的安卓设备上安装 ...
- PLSQL_developer安装与配置
前言: 记录安装与配置操作 环境: 客户机:windows 服务器:虚拟机中的windows server 2003 /---------------------------------------- ...
- 秋招还没Offer怎么办?
如果你是双非院线.没有实习经历.没有出众的技术(算法没刷一千道,也没做过 Spring Cloud 项目).现在还没有面试(或只有少量的面试).并且目前还没有 Offer,那么恭喜你,你和目前大部分同 ...
- Vue之class的用法
Vue中class的使用总结如下: 使用形式v-bind:class 简写:class 1.在数组中使用一个class <!DOCTYPE html> <html lang=&qu ...
- wireshark数据包时间戳修改
1.数据包格式 两种数据包格式,pcap和pcapng两种.pcapng为升级版,时间戳细粒度更高. 2.时间戳位置(arrival time) 时间戳在数据包中表现为物理层的arrival time ...
- Unity - UIWidgets 1. 从Hello world开始
安装参照github的README.UIWidgets相当于Flutter的一个Unity实现(后面表示UIWidgets和UGUI区别时直接称"Flutter"),是把承载的所有 ...
- PKUSC & GDCPC 2023 游记
离得太近,游记打算扔一起. 有没有神仙面基啊 /kel. PKUSC 2023 Day -? 突然听说不给 NOI Linux,震惊. 前情提要:在从 CSP 开始就全员强制 linux 的 LN 为 ...
- 自然数的拆分问题(lgP2404)
dfs.又调了一个小时,窝果然菜 需要传递的变量分别为目前搜索的数字:目前所有选中数字的和:目前所选数字个数. 见注释. #include<bits/stdc++.h> using nam ...