A.Eleven
A. Eleven
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
题意:fn的就是O,其他的就是o。
先讲string编程长度n的o然后a=1,b=1,a+b就变换为O,然后输出。
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define inf 1e9
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 1005;
int main(){
string s;
int n;
while(cin>>n){
if(n <= 2){
s=string(n,'O');
cout<<s<<endl;
continue;
}
s="OO"+string(n-2,'o');
int a=1,b=2;
int c=a+b;
while(c<=n){
s[c-1]='O';
a=b;
b=c;
c=a+b;
}
cout<<s<<endl;
}
return 0;
}
B. Radio Station
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 a, b, c 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, command only 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
这题就没弄懂他要干嘛。看样例。然后看着样例输出了。用了一个map用来对应两个字符串关系。
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define inf 1e9
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 1005;
map<string,string> mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
while(cin>>n>>m){
string s1,s2;
for(int i = 1 ; i <= n ; i++){
cin>>s1>>s2;
mp[s2] = s1;
}
for(int i = 1 ; i <= m ; i++){
cin>>s1>>s2;
cout<<s1<<" "<<s2<<" ";
int len = s2.length();
s2=s2.substr(0,len-1);
cout<<"#"<<mp[s2]<<endl;
}
}
return 0;
}
C. The Monster
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
从第一个读取。然后模拟这个过程,l,r模拟选取括号的过程。如果(l和r++。)l和r–。l==0那么就是匹配成功了ans++,如果r<0那么说明在前面)数量太多。肯定没办法匹配。那么直接break进入下次。如果是?就l–,r++,l<0的话l+=2。因为?有两种可能。假设前面(多,那么为)。此时l–,而r++表示他们中间的()数量。如果(没有。那么就为(此时l=-1 但是l+=2又让l=1。和(时一样。可以理解成。如果l=0也就是前面没有(那么?为(否则为)。
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define inf 1e9
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 5005;
string s;
int main(){
string s;
cin >> s;
ll ans = 0, l, r;
for(int i = 0; i < s.size(); i++){
l = r = 0;
if(s[i]== ')') continue;
for(int j = i; j < s.size(); j++){
if(s[j] == '(') l++, r++;
else if(s[j] == ')') l--, r--;
else l--, r++;
if(r < 0) break;
if(l < 0) l += 2;
if(l == 0) ans ++;
}
}
cout << ans << endl;
return 0;
}
D. MADMAX
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 v, u and a lowercase English letter c, meaning there’s an edge from v to u written c on it (1 ≤ v, u ≤ n, v ≠ 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
这个就是记忆化搜索。
每次dfs就是根据换人下棋将参数换位就行了。根据如果没有子节点或者没有可以走的子节点的人必输。
然后dp[_max][_max][26]。_max表示定点数。26表示此时的权。
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define inf 1e9
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 105;
vector<int> v[_max];
int mp[_max][_max];
int dp[_max][_max][26];
int dfs(int u,int p,int w){
if(dp[u][p][w]!=-1) return dp[u][p][w];
dp[u][p][w] = 0;
for(int i = 0 ; i < v[u].size() ; i++){
int s = v[u][i];
if(mp[u][s] >= w){
if(!dfs(p,s,mp[u][s])){
dp[u][p][w] = 1;
break;
}
}
}
return dp[u][p][w];
}
int main(){
memset(dp,-1,sizeof(dp));
int n,m;
cin>>n>>m;
int a,b;
char c;
while(m--){
cin>>a>>b>>c;
v[a].push_back(b);
mp[a][b]=int(c-'a');
}
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++)
if(dfs(i,j,0))
cout<<"A";
else
cout<<"B";
cout<<endl;
}
return 0;
}