洛谷 P4413 - [COCI2006-2007#2] R2

【题目描述】

The number S is called the mean of two numbers R1 and R2 if S is equal to (R1+R2)/2. Mirko's birthday present for Slavko was two integers R1 and R2. Slavko promptly calculated their mean which also happened to be an integer but then lost R2! Help Slavko restore R2.

【输入】

The first and only line of input contains two integers R1 and S, both between -1000 and 1000.

【输出】

Output R2 on a single line.

【输入样例】

11 15

【输出样例】

19

【算法分析】

这……………………

∵S=(R1+R2)/2

∴R2=2S-R1

【AC代码】

1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5     int s,r1;
6     cin>>r1>>s;
7     cout<<2*s-r1;
8     return 0;
9 }

猜你喜欢

转载自www.cnblogs.com/tyqEmptySet/p/10087860.html