Codeforces Round #459 (Div.2)-A&B

熬夜打CF结果今天老师讲课啥都没听233

A题题面 :

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

$f_1=1$,
$f_2 =1$,
$f_n = f_(n - 2) + f_(n - 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’组成的长度为$n$的子串,如果$i$为斐波那契数,则第$i$个字符为‘O’,其他输出‘o’

题解:

 看到题目一阵激动:“签到题赶紧虐

又发现限制$(1 ≤ n ≤1000)$

于是就不想推公式YY出了下面的代码:

 

 1 #include <map>
 2 #include <list>
 3 #include <cmath>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>//头文件大根堆
 8 using namespace std;
 9 int n;
10 int main()
11 {
12     cin>>n;
13     for (int i=1;i<=n;i++)
14     {
15         if (i==1||i==2||i==3||i==5||i==8||i==13||i==21||i==34||i==55||i==89||i==144||i==233||i==377||i==610||i==987)
16         cout<<"O";
17         else
18         cout<<"o";
19     }
20     return 0;
21 }

 

其实。。。手打感觉确实很好

B题题面:

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

 大意:

给你n个域名+IP和m个命令(操作+IP),以“命令+#IP对应的域名”的形式输出

题解:

有几个坑点:

1、命令最后有一个‘;’(卡掉了我的map)

2、输出“命令”与“#”之间有一个空格(说着就丢人)

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,M;
 4 string com[1005];
 5 string ip2[1005]; 
 6 map<string,string>m;
 7 int main()
 8 {
 9     cin>>n>>M;
10     for (int i=1;i<=n;i++)
11     {
12         string name;
13         string ip;
14         cin>>name>>ip;
15         string n_ip=ip+';';//坑点1
16         m[n_ip]=name;
17     }
18     for (int i=1;i<=M;i++)
19     {
20         cin>>com[i];
21         cin>>ip2[i];
22     }
23     for (int i=1;i<=M;i++)
24        cout<<com[i]<<' '<<ip2[i]<<' '<<'#'<<m[ip2[i]]<<endl;
25     return 0;               //坑点2↑
26 }

 

 

$Think;twice,code;once.$
原文地址:https://www.cnblogs.com/ttyclear/p/8387542.html