BZOJ1432 [ZJOI2009]Function

Description

Input

一行两个整数n; k。

Output

一行一个整数,表示n 个函数第k 层最少能由多少段组成。

Sample Input

1 1

Sample Output

1

HINT

对于100% 的数据满足1 ≤ k ≤ n ≤ 100。

 

正解:数学

解题报告:

  网上都没有题解,那我也不写了吧。

 1 //It is made by jump~
 2 #include <iostream>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <ctime>
 9 #include <vector>
10 #include <queue>
11 #include <map>
12 #include <set>
13 using namespace std;
14 typedef long long LL;
15 int n,k,ans;
16 
17 inline int getint()
18 {
19        int w=0,q=0; char c=getchar();
20        while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
21        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
22 }
23 
24 inline void work(){
25     n=getint(); k=getint(); if(n==1) ans=1; else ans=min(k,n-k+1)*2;
26     printf("%d",ans); 
27 }
28 
29 int main()
30 {
31   work();
32   return 0;
33 }
原文地址:https://www.cnblogs.com/ljh2000-jump/p/5870085.html