Where is Vasya?

Vasya stands in line with number of people p (including Vasya), but he doesn't know exactly which position he occupies. He can say that there are no less than b people standing in front of him and no more than apeople standing behind him. Find the number of different positions Vasya can occupy.

Input

As an input you have 3 numbers:

1. Total amount of people in the line;

2. Number of people standing in front of him

3. Number of people standing behind him

Examples

Line.WhereIsHe(3, 1, 1) // => 2 The possible positions are: 2 and 3
Line.WhereIsHe(5, 2, 3) // => 3 The possible positions are: 3, 4 and 5

The third parameter is not irrelavant and is the reason why (9,4,3) is 4 not 5
you have to satisfy both conditions
no less than bef people in front of him
and
no more than aft people behind him

as far as i can tell all the test cases are correct

9个人,前面的人不少于4个,后面的人不多于3个的话,可以占据6,7,8,9 是个位置

第五个位置,虽然前面是4个人,但是后面也是4个人。后面的人数超过3了,就不符合。

using System;

public class Line
{
public static int WhereIsHe(int p, int bef ,int aft)
{
// Your code is here...
int count=;
int a=;//people infront of him
int b=;//people behind him
for(int i=;i<=p;i++)
{
a=i-;
b=p-i;
if(a>=bef&&b<=aft)
{
count++;
}
}
return count;
}
}

使用Linq进行简化后:

using System;
using System.Linq;
public static int WhereIsHe(int p, int bef, int aft)
{
return Enumerable.Range(, p).Where(x => x - >= bef && p - x <= aft).Count();
}

其他人的解法

using System;

public class Line
{
public static int WhereIsHe(int p, int bef ,int aft)
{
return Math.Min(p-bef,aft+);
}
}

Where is Vasya?的更多相关文章

  1. Milliard Vasya's Function-Ural1353动态规划

    Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...

  2. CF460 A. Vasya and Socks

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  4. Codeforces Round #281 (Div. 2) D. Vasya and Chess 水

    D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分

    C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. codeforces 676C C. Vasya and String(二分)

    题目链接: C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

  8. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  9. Codeforces Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学

    C. Vasya and Petya's Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

随机推荐

  1. String inputStream file转化

    String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...

  2. asp.net 时间比较,常用于在某段时间进行操作

    DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零:  t1 小于 t2. 返回值等于零 : t1 等于 ...

  3. php常量运用注意

    多个文件引入,常量重复定义会失效,后者无法重复定义...靠

  4. Implement Custom Cache Dependencies in ASP.NET 1.x

    Code download available at:CuttingEdge0407.exe(128 KB)   Contents What's a Cache Dependency, Anyway? ...

  5. 1010. Radix (25)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  6. Eclipse开发Android报错Jar mismatch! Fix your dependencies

    常常打开工程,发现项目并没有错,但是会有一个红X,然后就生成不了. 发现两个版本不同的android-support-v4.jar在使用 打开window-show views-problems Ja ...

  7. envi中多波段图层叠加layer stacking

    Basic Tools——layer stacking 选择投影和输出的文件 波段1-7波段图层都叠加在一个文件中了

  8. 详解Google-ProtoBuf中结构化数据的编码

    本文的主要内容是google protobuf中序列化数据时用到的编码规则,但是,介绍具体的编码规则之前,我觉得有必要先简单介绍一下google protobuf.因此,本文首先会介绍一些google ...

  9. NSTImer重复执行任务

    问题 应用需要调度代码以在特定的时间执行.此外,你还想要重复执行任务. 解决方案 使用NSTimer调度代码以在特定的时间执行.为了使用NSTimer,你需要有日期对象与指向应用的运行循环的引用. 注 ...

  10. EXTJS 4.2 添加滚动条

    bodyStyle: 'overflow-x:hidden; overflow-y:scroll',//显示滚动 文章来源:http://www.cnblogs.com/exmyth/archive/ ...