Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索
2 seconds
256 megabytes
standard input
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?
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 a single integer representing the number of stewards which Jon will feed.
2
1 5
0
3
1 2 5
1
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个数 输出去掉最小值最大值的之后的数列的个数
题解:水
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
int minx=;
int maxn=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
minx=min(minx,a[i]);
maxn=max(maxn,a[i]);
}
int ans=;
if(minx==maxn){
printf("0\n");
return ;
}
else
{
for(int i=;i<=n;i++)
{
if(a[i]==minx)
ans++;
if(a[i]==maxn)
ans++;
}
}
printf("%d\n",n-ans);
return ;
}
2 seconds
256 megabytes
standard input
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?
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 the total number of 1s in the range l to r in the final sequence.
7 2 5
4
10 3 10
5
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分解之后的数列的长度
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
ll n,l,r;
map<ll,ll> dp;
ll dfs(ll x)
{
if(x!=)
dp[x]+=*dfs(x/)+;
return dp[x];
}
int main()
{
dp[]=;
scanf("%I64d %I64d %I64d",&n,&l,&r);
dp.clear();
ll m=n;
dfs(m);
ll re=;
for(ll i=l; i<=r; i++)
{
ll exm=n;
ll ans=;
while(exm)
{
if(ans+dp[exm/]+==i)
{
if(exm%==)
re++;
break;
}
else
{
if(ans+dp[exm/]>i)
exm/=;
else
{
if(ans+dp[exm/]==i)
{
re++;
break;
}
ans+=dp[exm/]+;
}
}
if(ans==i)
{
re++;
break;
}
}
}
printf("%I64d\n",re);
return ;
}
Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【博弈论】【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> ...
- 【概率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 ...
- 【基数排序】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 ...
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...
随机推荐
- 爬虫2.1-scrapy框架-两种爬虫对比
目录 scrapy框架-两种爬虫对比和大概流程 1. 传统spider爬虫 2. crawl型爬虫 3. 循环页面请求 4. scrapy框架爬虫的大致流程 scrapy框架-两种爬虫对比和大概流程 ...
- jQuery官网plugins栏目下那些不错的插件
前言: 很久以前就关注过jQuery官网plugins栏目下那些全是英文的插件,本人的英文水平很菜,想要全部看懂确实是件不易之事. 好在大部分的案例中都有 view-homepage 或 Try a ...
- python 文件编译成exe可执行文件。
pyinstaller打包方法: pyinstaller安装参考地址:http://www.pyinstaller.org/ pywin32的下载地址:https://sourceforge.net/ ...
- NTP错误总结
Ntp错误总结 解决ntp的错误 no server suitable for synchronization found 当用ntpdate -d 来查询时会发现导致 no server suita ...
- POJ 3487 The Stable Marriage Problem(稳定婚姻问题 模版题)
Description The stable marriage problem consists of matching members of two different sets according ...
- 《剑指offer》---两个栈实现队列
本文算法使用python3实现 1.题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 时间限制:1s:空间限制:32768K 2.思路描述: ...
- 开发iOS百度地图大头针可以重复点击
[self.mapView deselectAnnotation:view.annotation animated:YES];
- vagrant简单学习使用
1.安装vagrant 旧版本的vagrant可以在http://downloads.vagrantup.com/下载,支持的系统平台有mac,debian/ubuntu, centos,window ...
- mysql的my.cnf配置文件
[client]port = 3306default-character-set=utf8mb4socket = /var/run/mysqld/mysql.sock# user=david# pas ...
- 基本数据类型(int,bool,str)
目录: 1.int 数字类型 2.bool 布尔值 3.str 字符串类型 一.整型(int) 在python3中所有的整数都是int类型.但在python2中如果数据量 ...