设为首页 加入收藏

TOP

Codeforces Round #272 (Div. 2)(一)
2015-07-20 17:29:58 来源: 作者: 【 】 浏览:11
Tags:Codeforces Round #272 Div.

?

?

?

A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes

Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m.

What is the minimal number of steps making him climb to the top of the stairs that satisfies his condition?

Input

The single line contains two space separated integers n, m (0?n?≤?10000,?1?m?≤?10).

Output

Print a single integer — the minimal number of moves being a multiple of m. If there is no way he can climb satisfying condition print ?-?1 instead.

Sample test(s) Input
10 2
Output
6
Input
3 5
Output
-1
Note

For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.

For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.

?

#include 
   
     int main() { int n, m; scanf(%d %d, &n, &m); int temp = n / 2; if(n % 2) temp++; if(temp % m == 0) printf(%d , temp); else { temp = temp + m - temp % m; if(temp > n) printf(-1 ); else printf(%d , temp); } }
   

?

?

?

?

B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes

Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.

Each command is one of the following two types:

Go 1 unit towards the positive direction, denoted as '+' Go 1 unit towards the negative direction, denoted as '-'

But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).

You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?

Input

The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.

The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.

Lengths of two strings are equal and do not exceed 10.

Output

Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10?-?9.

Sample test(s) Input
++-+-
+-+-+
Output
1.000000000000
Input
+-+-
+-??
Output
0.500000000000
Input
+++
??-
Output
0.000000000000
Note

For the first sample, both s1 and s2 will lead Dreamoon to finish at the same position ?+?1.

For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {+-++, +-+-, +--+, +---} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.

For the third sample, s2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position ?+?3 is 0.

?

?

#include 
   
     #include 
    
      #include 
     
       char s1[15],s2[15]; int main() { scanf(%s %s,s1,s2); int p1=0, m1=0; int p2=0, m2=0; int size=(int)strlen(s1); int wh=
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇NYoj-5个数求最值 下一篇ZOJ - 3822 Domination (DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·求navicat for mysql (2025-12-26 13:21:33)
·有哪位大哥推荐一下m (2025-12-26 13:21:30)
·MySQL下载与安装教程 (2025-12-26 13:21:26)
·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)