A - Rating Goal


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

Takahashi is a user of a site that hosts programming contests.
When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:

  • Let the current rating of the user be a.
  • Suppose that the performance of the user in the contest is b.
  • Then, the new rating of the user will be the avarage of a and b.

For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.

Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.
Find the performance required to achieve it.

Constraints

  • 0≤R,G≤4500
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

R
G

Output

Print the performance required to achieve the objective.


Sample Input 1

Copy
2002
2017

Sample Output 1

Copy
2032

Takahashi's current rating is 2002.
If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.


Sample Input 2

Copy
4500
0

Sample Output 2

Copy
-4500

Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
using namespace std; const int N = + ; int c, n;
struct node{
int total_time = , total_solve = , num;
map<int, int> state;
}Node[N]; int main(){
double a, b;
cin >> a >> b;
cout << b * - a <<endl;
}

B - Addition and Multiplication


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value:

  • Operation A: The displayed value is doubled.
  • Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.

Constraints

  • 1≤N,K≤10
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.


Sample Input 1

Copy
4
3

Sample Output 1

Copy
10

The value will be minimized when the operations are performed in the following order: A, A, B, B.
In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.


Sample Input 2

Copy
10
10

Sample Output 2

Copy
76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.
In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
using namespace std; int main(){
int n, k;
int a = ;
cin >> n >> k;
for(int i = ; i <= n; i++){
if(a + k < * a) a += k;
else a *= ;
}
cout << a << endl;
}
#include<bits/stdc++.h>

using namespace std;

int n, k;

int DFS(int n, int val){
if(n == ) return val;
int a = DFS(n - , val * );
int b = DFS(n - , val + k);
return a > b ? b : a;
}
int main(){
cin >> n >> k;
cout << DFS(n, ) << endl;
}

C - Dubious Document 2


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.
He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

  • Condition 1: The string S contains a string T as a contiguous substring.
  • Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.
If such a string does not exist, print UNRESTORABLE.

Constraints

  • 1≤|S'|,|T|≤50
  • S' consists of lowercase English letters and ?.
  • T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.
If such a string does not exist, print UNRESTORABLE instead.


Sample Input 1

Copy
?tc????
coder

Sample Output 1

Copy
atcoder

There are 26 strings that satisfy Condition 1: atcoderbtcoderctcoder,..., ztcoder. Among them, the lexicographically smallest is atcoder, so we can say S=atcoder.


Sample Input 2

Copy
??p??d??
abc

Sample Output 2

Copy
UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S; void Work(){
int lens = s.size();
int lent = t.size();
for(int i = ; i < lens; i++){
if(s[i] == '?' || s[i] == t[]){
string tmp = s;
for(int j = ; j < i; j++) if(tmp[j] == '?') tmp[j] ='a';
bool can = false;
for(int j = ; j < lent; j++){
if(tmp[i+j]!= '?' && tmp[i+j] != t[j]) break;
tmp[i+j] = t[j];
if(j == lent - ) can = true;
}
if(can){
for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
S.insert(tmp);
}
}
}
if(S.size() == ) cout << "UNRESTORABLE" << endl;
else cout << *S.begin() << endl;
}
int main(){
cin >> s >> t;
Work();
}

最新文章

  1. linq语法大全(转集)
  2. (转)UIWebView全部API学习
  3. Spring——(一)IoC
  4. bootstrap弹框
  5. 使用Percona Toolkit解决Mysql主从不同步问题【备忘】
  6. ARM指令集(下)
  7. XCode 自动化打包总结
  8. 安卓 报错 Check the Eclipse log for stack trace.
  9. linux系统下mySQL数据库 备份方法和脚本
  10. ORACLE REFERENCES FRO TEST
  11. JSP标准标签库(JSTL)--函数标签库 fn
  12. pycharm安装和首次使用
  13. [题解]N 皇后问题总结
  14. &lt;&lt;梦断代码&gt;&gt;阅读笔记一
  15. uva10564
  16. [Hbase]Hbase容灾方案
  17. 人生第一次JAVA编程,电梯(并不算完成版),以及IDEA里使用git
  18. 免费素材:气球样式的图标集(PSD, SVG, PNG)
  19. [微信小程序]计算自己手机到指定位置的距离
  20. ED3 flash 、OBP flash

热门文章

  1. poj2386(dfs搜索水题)
  2. TTTTTTTTTTTT Codeforces Round #353 (Div. 2) D 平衡二叉树的set模拟 没有很懂
  3. Map循环/迭代/遍历效率、性能问题。
  4. 工具类-ApplicationContextUtil
  5. 自动化部署脚本之windows上执行批处理文件
  6. GC详解
  7. JS基础_强制类型转换
  8. Entity Framework Code First使用者的福音 --- EF Power Tool使用记之一
  9. C++11获取当前毫秒数
  10. 常用 tcpdump 抓包方式