A. Oath of the Night's Watch
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.

With that begins the watch of Jon Snow. He is assigned the task to support the stewards.

This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.

Can you find how many stewards will Jon support?

Input

First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.

Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.

Output

Output a single integer representing the number of stewards which Jon will feed.

Examples
Input
  1. 2
    1 5
Output
  1. 0
Input
  1. 3
    1 2 5
Output
  1. 1
Note

In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.

In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.

题意:给你n个数 输出去掉最小值最大值的之后的数列的个数

题解:水

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. int n;
  15. int a[];
  16. int main()
  17. {
  18. scanf("%d",&n);
  19. int minx=;
  20. int maxn=;
  21. for(int i=;i<=n;i++)
  22. {
  23. scanf("%d",&a[i]);
  24. minx=min(minx,a[i]);
  25. maxn=max(maxn,a[i]);
  26. }
  27. int ans=;
  28. if(minx==maxn){
  29. printf("0\n");
  30. return ;
  31. }
  32. else
  33. {
  34. for(int i=;i<=n;i++)
  35. {
  36. if(a[i]==minx)
  37. ans++;
  38. if(a[i]==maxn)
  39. ans++;
  40. }
  41. }
  42. printf("%d\n",n-ans);
  43. return ;
  44. }
B. Code For 1
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.

Initially Sam has a list with a single element n. Then he has to perform certain operations on this list. In each operation Sam must remove any element x, such that x > 1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.

Now the masters want the total number of 1s in the range l to r (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?

Input

The first line contains three integers n, l, r (0 ≤ n < 250, 0 ≤ r - l ≤ 105, r ≥ 1, l ≥ 1) – initial element and the range l to r.

It is guaranteed that r is not greater than the length of the final list.

Output

Output the total number of 1s in the range l to r in the final sequence.

Examples
Input
  1. 7 2 5
Output
  1. 4
Input
  1. 10 3 10
Output
  1. 5
Note

Consider first example:

Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.

For the second example:

Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5.

题意:给你一个数x  分成{x/2,x%2,x/2}  直到每一项为0或1  问你[l,r]内1的个数。

题解:对一个三叉树dfs  dp[x]表示 x分解之后的数列的长度

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. #include <map>
  10. #define ll __int64
  11. #define mod 1000000007
  12. #define dazhi 2147483647
  13. using namespace std;
  14. ll n,l,r;
  15. map<ll,ll> dp;
  16. ll dfs(ll x)
  17. {
  18. if(x!=)
  19. dp[x]+=*dfs(x/)+;
  20. return dp[x];
  21. }
  22. int main()
  23. {
  24. dp[]=;
  25. scanf("%I64d %I64d %I64d",&n,&l,&r);
  26. dp.clear();
  27. ll m=n;
  28. dfs(m);
  29. ll re=;
  30. for(ll i=l; i<=r; i++)
  31. {
  32. ll exm=n;
  33. ll ans=;
  34. while(exm)
  35. {
  36. if(ans+dp[exm/]+==i)
  37. {
  38. if(exm%==)
  39. re++;
  40. break;
  41. }
  42. else
  43. {
  44. if(ans+dp[exm/]>i)
  45. exm/=;
  46. else
  47. {
  48. if(ans+dp[exm/]==i)
  49. {
  50. re++;
  51. break;
  52. }
  53. ans+=dp[exm/]+;
  54. }
  55. }
  56. if(ans==i)
  57. {
  58. re++;
  59. break;
  60. }
  61. }
  62. }
  63. printf("%I64d\n",re);
  64. return ;
  65. }

Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索的更多相关文章

  1. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  2. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  3. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

  6. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  7. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  8. 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...

  9. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

随机推荐

  1. 关于java获取网页内容

    最近项目需求,做一些新闻站点的爬取工作.1.简单的jsoup爬取,静态页面形式: String url="a.atimo.cn";//静态页面链接地址Document doc = ...

  2. 【shell 练习4】编写Shell用户管理脚本(二)

    一.创建.删除.查看用户,随机生成八位数密码 #!/bin/bash #Author:yanglt #!/bin/bash #Author:yanglt #Blog:https://www.cnblo ...

  3. 【机器学习】多项式回归sklearn实现

    [机器学习]多项式回归原理介绍 [机器学习]多项式回归python实现 [机器学习]多项式回归sklearn实现 使用sklearn框架实现多项式回归.使用框架更方便,可以少写很多代码. 使用一个简单 ...

  4. 改maven下创建的动态网站依赖的jre版本

    问题描述 通过maven创建一个动态网站后,eclipse会提示一个提醒 Build path specifies execution environment J2SE-1.5. There are ...

  5. Python3 小工具-ARP欺骗

    在kali中使用 from scapy.all import * import optparse import os def send(pkt,interface): for p in pkt: se ...

  6. java面试整理

    IO和NIO的区别 这是一个很常见的问题,如果单纯的只回答IO和NIO的区别,只能算及格.我个人觉得应该从以下几个方面回答: 1).IO简介, 2).TCP的三次握手,因为这也是两者的区别之一, 3) ...

  7. array.some() 方法兼容ie8

    在第 5 版时,some 被添加进 ECMA-262 标准:这样导致某些实现环境可能不支持它.你可以把下面的代码插入到脚本的开头来解决此问题,从而允许在那些没有原生支持它的实现环境中使用它.该算法是  ...

  8. CSS基础小记

    2017/10/29 CSS 认识CSS样式 CSS全称为"层叠样式表 (Cascading Style Sheets)",它主要是用于定义HTML内容在浏览器内的显示样式,如文字 ...

  9. 3dContactPointAnnotationTool开发日志(七)

      调了半天发现是逻辑错误,改了一下终于没那么奇怪了:   但是有的接触点很明显跑偏了.再回顾一下自己是怎么求的,我是直接用的下面的代码求解一个点是否在另一个物体内部: var bounds = us ...

  10. PokeCats开发者日志(十二)

      现在是PokeCats游戏开发的第六十一天的晚上,终于拿到软著权登记证书了!   看来易版权确实是个值得信赖的代办机构呢,400块花的不冤.