又掉分了0 0。

A. Scarborough Fair
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Are you going to Scarborough Fair?

Parsley, sage, rosemary and thyme.

Remember me to one who lives there.

He once was the true love of mine.

Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.

Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.

Although the girl wants to help, Willem insists on doing it by himself.

Grick gave Willem a string of length n.

Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (froml-th to r-th, including l and r) are changed into c2. String is 1-indexed.

Grick wants to know the final string after all the m operations.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100).

The second line contains a string s of length n, consisting of lowercase English letters.

Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ nc1, c2 are lowercase English letters), separated by space.

Output

Output string s after performing m operations described above.

Examples
input
3 1
ioi
1 1 i n
output
noi
input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
output
gaaak

中规中矩的水题。
 #include<bits/stdc++.h>
using namespace std;
char s[];
int main()
{
int n,m,k,T,l,r;
char o,p;
scanf("%d%d",&n,&m);
scanf("%s",s);
for(int i=;i<=m;i++)
{
scanf("%d%d %c %c",&l,&r,&o,&p);
for(int i=l-;i<=r-;i++)
if(s[i]==o)
s[i]=p;
}
printf("%s\n",s);
return ;
}
B. Chtholly's request
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number ispalindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples
input
2 100
output
33
input
5 30
output
15

枚举下各位的情况就好了,最多12位的回文数。
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int n,k;
LL ans,mod;
void dfs(int lf,int sign,LL num)
{
if(k==)
return ;
if(lf==)
{
LL p=num;
while(p)
{
num*=;
num+=p%;
p/=;
}
ans=(ans+num%mod)%mod;
k--;
return ;
}
if(sign)
for(int i=;i<=;i++)
dfs(lf-,,num*+i);
else
for(int i=;i<=;i++)
dfs(lf-,,num*+i);
return ;
}
int main()
{
scanf("%d%lld",&k,&mod);
ans=;
for(int p=;p<=;p++)
{
if(k==)
break;
dfs(p,,);
}
printf("%lld\n",ans);
return ;
}
C. Nephren gives a riddle
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

What are you doing at the end of the world? Are you busy? Will you save us?

Nephren is playing a game with little leprechauns.

She gives them an infinite array of strings, f0... ∞.

f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".

She wants to let more people know about it, so she defines fi =  "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.

For example, f1 is

"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.

It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.

Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).

Can you answer her queries?

Input

The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.

Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).

Output

One line containing q characters. The i-th character in it should be the answer for the i-th query.

Examples
input
3
1 1
1 2
1 111111111111
output
Wh.
input
5
0 69
1 194
1 139
0 47
1 66
output
abdef
input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
output
Areyoubusy

最多到f50因此动态计算下fi的长度。这些都可以拿到dfs里去算,然后已经算出来长度的该跳过去的就跳过去。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
string s0=" What are you doing at the end of the world? Are you busy? Will you save us?";
string spre=" What are you doing while sending \"";
string son=" \"? Are you busy? Will you send \"";
string slast=" \"?";
int n,m,t,p,now,s0size=s0.size()-,spresize=spre.size()-,sonsize=son.size()-,slastsize=slast.size()-;
LL k;
bool flag;
LL ss[N];
int T;
void dfs(int n,LL pos)
{
if(flag)
return ;
if(n==)
{
if(pos+s0size>=k)
{
printf("%c",s0[k-pos]);
flag=;
return ;
}
else
return ;
}
if(pos+spresize>=k)
{
printf("%c",spre[k-pos]);
flag=;
return ;
}
else
pos+=spresize;
if(ss[n-]==)
{
dfs(n-,pos);
pos+=ss[n-];
}
else
{
if(pos+ss[n-]>=k)
dfs(n-,pos);
else
pos+=ss[n-];
}
if(flag)
return ;
if(pos+sonsize>=k)
{
printf("%c",son[k-pos]);
flag=;
return ;
}
else
pos+=sonsize;
if(pos+ss[n-]>=k)
dfs(n-,pos);
else
pos+=ss[n-];
if(flag)
return ;
if(pos+slastsize>=k)
{
printf("%c",slast[k-pos]);
flag=;
return ;
}
else
pos+=slastsize;
ss[n]=spresize+ss[n-]+sonsize+ss[n-]+slastsize;
return ;
}
int main()
{
ss[]=s0size;
scanf("%d",&T);
while(T--)
{
scanf("%d%lld",&n,&k);
flag=;
dfs(n,);
if(!flag)
printf(".");
}
printf("\n");
return ;
}
D. Ithea Plays With Chtholly
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is an interactive problem. Refer to the Interaction section below for better understanding.

Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.

Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right.

This game will go on for m rounds. In each round, Ithea will give Chtholly an integer between 1 and c, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).

Chtholly wins if, at any time, all the sheets are filled with a number and the n numbers are in non-decreasing order looking from left to right from sheet 1 to sheet n, and if after m rounds she still doesn't win, she loses the game.

Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.

Input

The first line contains 3 integers n, m and c ( means  rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.

Interaction

In each round, your program needs to read one line containing a single integer pi (1 ≤ pi ≤ c), indicating the number given to Chtholly.

Your program should then output a line containing an integer between 1 and n, indicating the number of sheet to write down this number in.

After outputting each line, don't forget to flush the output. For example:

  • fflush(stdout) in C/C++;
  • System.out.flush() in Java;
  • sys.stdout.flush() in Python;
  • flush(output) in Pascal;
  • See the documentation for other languages.

If Chtholly wins at the end of a round, no more input will become available and your program should terminate normally. It can be shown that under the constraints, it's always possible for Chtholly to win the game.

Example
input
2 4 4
2
1
3
output
1
2
2

很有意思的是,m≥n*[c/2]就能保证形成非严格递增的序列,我们可以从这里切入。

那么我们从[c/2]入手。把新加入的数分为小于等于[c/2]和大于[c/2]两类。如果初始序列前半部分(长度不定)都是小于等于[c/2],后半部分都是大于[c/2],那么对于前半部分每个数字做最多[c/2]-1次向更小的数替换,后半部分做最多c-[c/2]-1次向更大数的替换,就能得到要求序列。那么总次数最多就是题目中的n*[c/2]了,也就是在m次能得到答案。那么我有一个大胆的想法:遇到小于等于[c/2],从头到尾找第一个空位置或者大于它的数替换,大于[c/2],从尾到头找第一个空位置或小于它的数替换,能达到上述的效果。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e4+;
int a[N];
bool flag;
int main()
{
int n,m,p,now,c;
scanf("%d%d%d",&n,&m,&c);
for(int i=;i<=m;i++)
{
scanf("%d",&p);
if(p*<=c)
{
for(int j=;j<=n;j++)
if(a[j]== || a[j]>p)
{
a[j]=p;
printf("%d\n",j);
fflush(stdout);
break;
}
}
else
{
for(int j=n;j>=;j--)
if(a[j]== || a[j]<p)
{
a[j]=p;
printf("%d\n",j);
fflush(stdout);
break;
}
}
flag=;
for(int i=;i<=n;i++)
if(a[i]== || a[i]<a[i-])
{
flag=;
break;
}
if(a[]==) flag=;
if(flag)
return ;
}
}

Codeforces Round #449 (Div. 2)ABCD的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. Codeforces Round #449 (Div. 2)

    Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  5. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  6. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  7. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  9. Codeforces Round #412 (Div. 2)ABCD

    tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...

随机推荐

  1. 【NOIP】2013 花匠

    [算法]贪心 [题解] DP可以f[i][0],f[i][1]表示选了i分别满足条件AB的答案,其优化也是利用了下面的性质,不多赘述. 想象数列的波动,最大值一定是取每个波峰和每个波谷,那么只要O(n ...

  2. 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    [算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...

  3. 【洛谷 P2783】 有机化学之神偶尔会做作弊 (双联通分量)

    题目链接 可能是除了<概率论>的最水的黑题了吧 用\(Tarjan\)缩点(点双联通分量),然后就是树上两点之间的距离了,跑\(LCA\)就好了. #include <cstdio& ...

  4. new操作符的内部运行解析

    在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在Javascript中,我们将这类方式成为Pseudoclassical. 基于上面的例子,我们执行如下代码   ...

  5. c语言中的size_t

    size_t unsigned int 类型,无符号,它的取值没有负数.用来表示 参数/数组元素个数,sizeof 返回值,或 str相关函数返回的 size 或 长度.sizeof 操作符的结果类型 ...

  6. Django 1.10中文文档-第一个应用Part4-表单和通用视图

    本教程接Part3开始.继续网页投票应用程序,并将重点介绍简单的表单处理和精简代码. 一个简单表单 更新一下在上一个教程中编写的投票详细页面的模板polls/detail.html,让它包含一个HTM ...

  7. 原始套接字&&数据链路层访问

    1. 原始套接字能力: (1) 进程可以读写ICMP,IGMP等分组,如ping程序: (2) 进程可以读写内核不处理协议字段的ipv4数据报:如OSPF等: (3) 进程可以使用IP_HDRINCL ...

  8. U-Boot启动过程完全分析<转>

    转载自:http://www.cnblogs.com/heaad/archive/2010/07/17/1779829.html 1.1       U-Boot工作过程 U-Boot启动内核的过程可 ...

  9. twemproxy 简介、安装配置

    twemproxy 简介.安装配置 http://www.xuchanggang.cn/archives/993.html

  10. Mac下使用brew搭建PHP7+nginx+mysql开发环境

    http://blog.csdn.net/mysteryhaohao/article/details/52230634 HomeBrew brew的安装,直接上官网:http://brew.sh/ 一 ...