A. Eleven
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.

Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where

  • f1 = 1,
  • f2 = 1,
  • fn = fn - 2 + fn - 1 (n > 2).

As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

Input

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Output

Print Eleven's new name on the first and only line of output.

Examples
input
8
output
OOOoOooO
input
15
output
OOOoOooOooooOoo

是菲波那切数列的数输出O,否则输出o,只要15项就行了(脑残了把房间的那个hack

#include<bits/stdc++.h>
using namespace std;
int a[],f[],n;
int main()
{
f[]=,f[]=;
for(int i=;f[i]<=;i++)
f[i+]=f[i]+f[i-],a[f[i]]=;
cin>>n;
for(int i=;i<=n;i++)
if(a[i]==)cout<<"O";
else cout<<"o";
return ;
}
B. Radio Station
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.

Each ip is of form "a.b.c.d" where abc and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.

Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 1000).

The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≤ |name| ≤ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct.

The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≤ |command| ≤ 10, commandonly consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.

Output

Print m lines, the commands in the configuration file after Dustin did his task.

Examples
input
2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1;
proxy 192.168.0.2;
output
block 192.168.0.1; #replica
proxy 192.168.0.2; #main
input
3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;
output
redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; #codeforces
unblock 8.8.8.8; #google
check 138.197.64.57; #server
一对一的,一个IP对应一个服务器,所以直接map就行了(脑残了想的有点多

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
map<string,string>M;
string s,c;
for(int i=;i<n;i++)
{
cin>>s>>c;
M[c]=s;
}
for(int i=;i<m;i++)
{
cin>>s>>c;
cout<<s<<" "<<c<<" #"<<M[c.substr(,c.length()-)]<<"\n";
}
return ;
}
C. The Monster
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.

Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.

A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:

  • Empty string is a correct bracket sequence.
  • if s is a correct bracket sequence, then (s) is also a correct bracket sequence.
  • if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence.

A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.

Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s.

Joyce doesn't know anything about bracket sequences, so she asked for your help.

Input

The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000).

Output

Print the answer to Will's puzzle in the first and only line of output.

Examples
input
((?))
output
4
input
??()??
output
7
Note

For the first sample testcase, the pretty substrings of s are:

  1. "(?" which can be transformed to "()".
  2. "?)" which can be transformed to "()".
  3. "((?)" which can be transformed to "(())".
  4. "(?))" which can be transformed to "(())".

For the second sample testcase, the pretty substrings of s are:

  1. "??" which can be transformed to "()".
  2. "()".
  3. "??()" which can be transformed to "()()".
  4. "?()?" which can be transformed to "(())".
  5. "??" which can be transformed to "()".
  6. "()??" which can be transformed to "()()".
  7. "??()??" which can be transformed to "()()()".

?可以填(),然后判断这个括号序列是不是合法

死活出不了,因为自己没有想到这个贪心,我也想到了要去判断每个序列是不是合法
左括号是不能限制序列的,又括号的好就不能出现多余的了,但是?能代替左右,假设其代替左,那么l小于0的时候,就要把?变了,如果不合法的话,r不合法就检查下一序列了,其他的继续
非常巧妙
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int ans=;
for(int i=;s[i];i++)
{
int l=,r=;
for(int j=i;s[j];j++)
{
if(s[j]=='(')l++,r++;
else if(s[j]==')')l--,r--;
else l--,r++;
if(l<)l+=;
if(r<)break;
if(!l)ans++;
}
}
cout<<ans;
return ;
}
D. MADMAX
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lowercase English letter.

Max and Lucas are playing the game. Max goes first, then Lucas, then Max again and so on. Each player has a marble, initially located at some vertex. Each player in his/her turn should move his/her marble along some edge (a player can move the marble from vertex v to vertex u if there's an outgoing edge from v to u). If the player moves his/her marble from vertex v to vertex u, the "character" of that round is the character written on the edge from v to u. There's one additional rule; the ASCII code of character of round i should be greater than or equal to the ASCII code of character of round i - 1 (for i > 1). The rounds are numbered for both players together, i. e. Max goes in odd numbers, Lucas goes in even numbers. The player that can't make a move loses the game. The marbles may be at the same vertex at the same time.

Since the game could take a while and Lucas and Max have to focus on finding Dart, they don't have time to play. So they asked you, if they both play optimally, who wins the game?

You have to determine the winner of the game for all initial positions of the marbles.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 100, ).

The next m lines contain the edges. Each line contains two integers vu and a lowercase English letter c, meaning there's an edge from vto u written c on it (1 ≤ v, u ≤ nv ≠ u). There's at most one edge between any pair of vertices. It is guaranteed that the graph is acyclic.

Output

Print n lines, a string of length n in each one. The j-th character in i-th line should be 'A' if Max will win the game in case her marble is initially at vertex i and Lucas's marble is initially at vertex j, and 'B' otherwise.

Examples
input
4 4
1 2 b
1 3 a
2 4 c
3 4 b
output
BAAA
ABAA
BBBA
BBBB
input
5 8
5 3 h
1 2 c
3 1 c
3 2 r
5 1 r
4 3 z
5 4 r
5 2 h
output
BABBB
BBBBB
AABBB
AAABA
AAAAB
Note

Here's the graph in the first sample test case:

Here's the graph in the second sample test case:

它是一个DAG,所以直接记忆化搜索就行了,我太蠢了
#include<bits/stdc++.h>
using namespace std;
const int N=;
int SG[][][];
int head[],nxt[],to[],f[];
int tot;
int DFS(int i,int j,int k)
{
if(SG[i][j][k])return SG[i][j][k];
for(int p=head[i]; p; p=nxt[p])
if(f[p]>=k&&!DFS(j,to[p],f[p]))SG[i][j][k]=;
return SG[i][j][k];
}
void add(int u,int v,int w)
{
nxt[++tot]=head[u],head[u]=tot,to[tot]=v,f[tot]=w;
}
int main()
{
int n,m;
char c;
cin>>n>>m;
for(int i=,u,v; i<=m; i++)cin>>u>>v>>c,add(u,v,c-'a');
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
if(DFS(i,j,))cout<<'A';
else cout <<'B';
cout<<"\n";
}
return ;
}

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

  1. Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈

    D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  2. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...

  3. Codeforces Round #459 (Div. 2):B. Radio Station

    B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...

  4. Codeforces Round #459 Div. 1

    C:显然可以设f[i][S]为当前考虑到第i位,[i,i+k)的状态为S的最小能量消耗,这样直接dp是O(nC(k,x))的.考虑矩阵快速幂,构造min+转移矩阵即可,每次转移到下一个特殊点然后暴力处 ...

  5. Codeforces Round #459 (Div. 2)-A. Eleven

    A. Eleven time limit per test1 second memory limit per test256 megabytes Problem Description Eleven ...

  6. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    题意 在一个有向无环图上,两个人分别从一个点出发,两人轮流从当前点沿着某条边移动,要求经过的边权不小于上一轮对方经过的边权(ASCII码),如果一方不能移动,则判负.两人都采取最优策略,求两人分别从每 ...

  7. Codeforces Round #459 (Div. 2)The Monster[匹配问题]

    题意 给一个序列,包含(,),?,?可以被当做(或者),问你这个序列有多少合法的子序列. 分析 n^2枚举每一个子序列,暂时将每个?都当做右括号,在枚举右端点的时候同时记录两个信息:当前左括号多余多少 ...

  8. Codeforces Round #459 (Div. 2)C. The Monster

    C. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. 【Codeforces Round #459 (Div. 2) B】 Radio Station

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map模拟一下映射就好了. [代码] #include <bits/stdc++.h> using namespace ...

随机推荐

  1. Got error 28 from storage engine的错误处理

    早上例行检查数据库,发现Got error 28 from storage engine这个错误,天那,我的数据.心里哇凉....备份的时间还是很久以前.最近更新了不少,麻烦大了. 好在找到了解决方法 ...

  2. 监测元素resize

    前言 近来有需求要做分页,听起来可能有点Low. 所以我要把Low的事情做得有点逼格. 分页本身没啥,但是数据量起来了,比如十万. 要是不做点处理, 那你的页面估计爽得很,机器也爽得很. 放心,我不会 ...

  3. ThinkPHP笔记——开启debug调试模式

    debug+trace模式可以查看开发过程中TP的错误信息,可以更好地帮助开发者debug.但是debug模式的开启还不是简单的在配置文件中中设置就可以的,经过查资料摸索,找到一种有效的方法. 首先在 ...

  4. c#中的里氏转换和Java中强制类型转换在多态中的应用

    在c#中: 注意: 子类并没有继承父类的构造函数,而是会默认调用父类那个无参数的构造函数. 如果一个子类继承了一个父类,那么这个子类除了可以使用自己的成员外,还可以使用从父类那里继承过来的成员.但是父 ...

  5. Bootstrap历练实例:标签页内的下拉菜单

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  6. Eclipse:Win10中设置Courier New字体

    问题:在Eclipse中设置字体的时候,没有找到Courier New字体.系统为Win10. 解决:Eclipse使用的字体为系统字体.在系统字体中有一部分是隐藏的.Courier New已经在系统 ...

  7. shell脚本,awk取奇数行与偶数行方法。

    第一种方法: 第二种方法: 第三种方法:

  8. 机器学习十大常用算法(CITE 不会停的蜗牛 ) interesting

    算法如下: 决策树 随机森林算法 逻辑回归 SVM 朴素贝叶斯 K最近邻算法 K均值算法 Adaboost 算法 神经网络 马尔可夫 1. 决策树 根据一些 feature 进行分类,每个节点提一个问 ...

  9. 如何理解JavaScript中的this关键字

    前言 王福朋老师的 JavaScript原型和闭包系列 文章看了不下三遍了,最为一个初学者,每次看的时候都会有一种 "大彻大悟" 的感觉,而看完之后却总是一脸懵逼.原型与闭包 可以 ...

  10. 在VMware上安装centos7

    1. 下载centos7 64位镜像 linux官网下载:https://www.centos.org/download/ 2. 在VMware上安装centos7 2.1 新建虚拟机 打开虚拟机主页 ...