codeforces 897 D Ithea Plays With Chtholly(交互)
来源:互联网 发布:做数据是什么 编辑:程序博客网 时间:2024/05/11 18:01
题意:
每次给你一个数,让你放到一个长度为n 的数组里,直到这个数组填满并且是不递减函数为止。需要 在m步内完成
c是给出的数的范围。
解题思路:
一种显然的暴力方法就是从1开始扫描,遇到第一个大于x的或是a[i]==0的就放。
但是还有显然的卡掉这种暴力的做法,就是把数n-1逐个给出,就每次要替换,这样的话就需要n^2次,显然不行。
所以应该能想到从两边,开始扫描,让大于c/2的从n开始往下扫描,这样刚刚那组数据就可以过了,复杂度正好是n*c/2。
赛时想到往两边放了,但是产生了需要开两个数组的错觉,然后无法合并两个数组,就开始乱搞了。。其实放一个数组里两种不同方法就能搞定,这需要抽象一下。。。
代码:
#include <bits/stdc++.h>#define LL long longusing namespace std;const int maxn=1e5+5;const LL inf=1e18+7;LL dp[maxn];char str1[100]="What are you doing at the end of the world? Are you busy? Will you save us?";char str2[100]="What are you doing while sending \"@\"? Are you busy? Will you send \"@\"?";int l1, l2;char solve(int n, LL k){ if(n==0)return str1[k-1]; int i, j; for(i=0; i<l2; i++) { if(str2[i]=='@') { if(dp[n-1]>=k) { return solve(n-1, k); } k-=dp[n-1]; } else { k--; if(k==0) { return str2[i]; } } } return '.';}int main(){ l1=strlen(str1); l2=strlen(str2); dp[0]=l1; for(int i=1; i<=100000; i++) { dp[i]=min(dp[i-1]*2LL+l2-2LL, inf); } int n, q, i, j; LL k; cin>>q; while(q--) { cin>>n>>k; if(k>dp[n]) { printf("."); } else printf("%c", solve(n, k)); } }
阅读全文
0 0
- codeforces 897 D Ithea Plays With Chtholly(交互)
- CodeForce 897 D. Ithea Plays With Chtholly
- Codeforces 896B Ithea Plays With Chtholly 交互/构造
- Codeforces Round #449 (Div. 1) B. Ithea Plays With Chtholly
- CodeForce896 B. Ithea Plays With Chtholly
- CodeForce896 B. Ithea Plays With Chtholly
- codeforces 757e Bash Plays with Functions
- Codeforces 757E Bash Plays with Functions
- [数论]Codeforces 757E. Bash Plays with Functions
- BJ模拟(1) D2T1 Bash Plays with Functions
- [Codeforces 897E. Willem, Chtholly and Seniorious]概率随机+set
- Codeforces Round #449 (Div. 2) 897B. Chtholly's request
- [easy]CodeForces-897B Chtholly's request 模拟/找规律
- CodeForces 637D Running with Obstacles(贪心模拟)
- CodeForces 637 D.Running with Obstacles(贪心)
- CodeForces 317 D.Game with Powers(博弈论)
- codeforces 897 B. Chtholly's request【构造回文数+递推】
- Codeforces Round #449 (Div. 2) B Chtholly's request (预处理)
- 鲍捷 | 知识图谱从 0 级到 10 级简化版
- C#算法系列(5)——希尔排序、堆排序
- centos 挂载 NTFS 分区 以及 解决 linux 下 MATLAB 中文乱码问题
- 记录蓝桥班的第一个代码
- HTML5 Web存储
- codeforces 897 D Ithea Plays With Chtholly(交互)
- 三维几何基础(3D?)
- 枚举(enum)类型
- 原生Ajax的原理和实现
- 【深度学习】Ubuntu16.04+tensorflow+opencv+pygame 运行FlappyBird(像素小鸟)代码(4)
- 工厂模式(Factory Pattern)
- R语言绘图边框
- MongoDB Java使用指南
- 设计模式-几个原则