Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]
PROBLEM C/A. Nephren gives a riddle
题
http://codeforces.com/contest/896/problem/A
codeforces 896a 897c
解
预第i个串的长度,由于k最大1e18,所以超过1e18的长度直接标记为无限大,不用计算
然后递归搜索即可
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; typedef long long ll; const ll INF=3e18;
const ll M=1e4+44;
const ll N=1e5+44; char f0[M]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
char s1[M]={"What are you doing while sending \""};
char s2[M]={"\"? Are you busy? Will you send \""};
char s3[M]={"\"?"};
ll lf0,ls1,ls2,ls3;
ll q;
ll len[N]; char solve(ll n,ll k)
{
if(n==0)
return f0[k-1];
if(k<=ls1)
return s1[k-1];
k-=ls1;
if(k<=len[n-1])
return solve(n-1,k);
k-=len[n-1];
if(k<=ls2)
return s2[k-1];
k-=ls2;
if(k<=len[n-1])
return solve(n-1,k);
k-=len[n-1];
return s3[k-1];
} int main()
{
ll n,k;
lf0=strlen(f0);
ls1=strlen(s1);
ls2=strlen(s2);
ls3=strlen(s3);
len[0]=lf0;
for(ll i=1;i<=100000;i++)
len[i]=3e18;
for(ll i=1;i<=100000;i++)
{
len[i]=len[i-1]*2+ls1+ls2+ls3;
if(len[i]>1e18)
break;
}
scanf("%I64d",&q);
while(q--)
{
scanf("%I64d%I64d",&n,&k);
if(k>len[n])
cout<<".";
else cout<<solve(n,k);
}
return 0;
}
PROBLEM D/B. Ithea Plays With Chtholly
题
http://codeforces.com/contest/896/problem/B
codeforces 986b 897d
解
从第一个位置开始维持一个从左到右不下降的序列,记为左序列;从左右一个位置开始维持一个从右到左不上升的序列,记为右序列
取中间值midpi=c/2,每次取到一个数,如果这个数小于等于midpi,放入左边的序列,并且维持左序列从左到右不下降;
如果这个数大于midpi,放入右序列,并且维持右序列从右到左不上升。
相遇即是成功
这样最坏情况不超过题目要求
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; const int M=1e3+44; int n,m,c,num,midpi;
int mp[M];
int s[M],li1,li2,ri1,ri2,flagli,flagri; bool check()
{
// for(int j=1;j<=n;j++)
// cout<<s[j]<<' ';
// cout<<endl;
for(int i=1;i<=n;i++)
if(s[i]==-1)
return false;
for(int i=1;i<n;i++)
if(s[i]>s[i+1])
return false;
// cout<<"true"<<endl;
return true;
} void xf()
{
fflush(stdout);
scanf("%d",&num);
} bool answer(int ans)
{
printf("%d\n",ans);
s[ans]=num;
if(check())
{
fflush(stdout);
return true;
}
else
{
fflush(stdout);
scanf("%d",&num);
return false;
}
} void init()
{
int a,b,pi=0;
a=c/n; b=c%n;
for(int i=1;i<=b;i++)
for(int j=1;j<=a+1;j++)
mp[++pi]=i;
for(int i=b+1;i<=n;i++)
for(int j=1;j<=a;j++)
mp[++pi]=i;
} void solve()
{
// init();
memset(s,-1,sizeof(s));
int flag;
midpi=c/2;
li1=1; li2=n/2; ri1=li2+1; ri2=n;
flagli=flagri=0;
for(int i=1;i<=m;i++)
{
// cout<<"id:"<<i<<endl;
if(num<=midpi)
{
for(int j=li1;j<=ri2;j++)
if(s[j]==-1 || s[j]>num)
if(answer(j))
return ;
else break;
}
else
{
for(int j=ri2;j>=li1;j--)
if(s[j]==-1 || s[j]<num)
if(answer(j))
return ;
else break;
}
}
} int main()
{
scanf("%d%d%d",&n,&m,&c);
xf();
solve();
return 0;
} /* 3 12 7
4
5 */
Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]的更多相关文章
- Codeforces Round #449 (Div. 2)
Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly
http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...
- Codeforces Round #449
960 asteri 1384 492 00:04 -1 892 01:33 960 PEPElotas 1384 488 00:06 896 00:26 960 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
- Codeforces Round #449 (Div. 2) C. DFS
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #449 Div. 2 A B C (暂时)
A. Scarborough Fair 题意 对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符. 思路 直接模拟 Code #include < ...
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
随机推荐
- 腾讯云服务器的CPU ---发现大厂都很那啥
今天给同事看了下 腾讯云上面的ora从了数据库的启动问题 简单看了下 硬件配置如下: System: Host: VM_0_8_centos Kernel: -.el6.x86_64 x86_64 b ...
- peewee无外键连接
# 参考:https://blog.csdn.net/weixin_34273479/article/details/87587183 res = Name.select(Name, User.xxx ...
- 转 RTSP客户端模拟器(TCP方式,Python实现)
转自: http://www.cnblogs.com/MikeZhang/archive/2012/10/29/rtspTcpClient_DSS_20121029.html 由于某种需求,工作中需要 ...
- 怎样使用 Vue 的监听属性 watch ?
需求: 我需要在某个数据变化时能够执行特定的动作, 比如我在输入框中输入数字 88, 系统检测到以后就会弹窗 拜拜 , 而输入其他字符则不会触发, 这种需求简直多入牛毛, 实际上这就是 自定义事件 , ...
- nignx简单介绍
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- Linq操作之Except,Distinct,Left Join 【转】
最近项目中用到了Linq中Except,Distinct,Left Join这几个运算,这篇简单的记录一下这几种情形. Except 基础类型使用Linq的运算很简单,下面用来计算两个集合的 ...
- Kendall tau距离(即两个内容相同的数组中逆序数对的数量)(算法》P220 第2.5.3.2小节)
一组排列就是一组N个整数的数组,其中0~N-1的每个数都只出现一次.两个排列之间的 Kendall tau距离就是在两组排列中相对顺序不同的数对的数目.例如,0 3 1 6 2 5 4和1 0 3 6 ...
- cpp编码规范要求
1.所有头文件使用#ifndef #define #endif来防止文件被多重包含,命名格式当是: <PROJECT>_<PATH>_<FILE>_H_ 2.只有当 ...
- deep_learning_Activate_method
常见的激活函数有sigmoid.tanh和relu三种非线性函数,其数学表达式分别为: sigmoid: y = 1/(1 + e-x) tanh: y = (ex - e-x)/(ex + e-x) ...
- DBUtils封装数据库返回对象的各种方法
①ArrayHandler: 将查询结果的第一行数据,保存到Object数组中 ②ArrayListHandler 将查询的结果,每一行先封装到Object数组中,然后将数 ...