交互题(apio2016Gap)
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include "gap.h"
using namespace std;
#define ll long long
#define db double
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i) ll findGap(int T,int N) {
ll n=(N+1)>>1,l=0,r=1e18,ld,rd,rs=0,fl=0,len;
if(T==1) {
MinMax(l,r,&ld,&rd); l=ld; r=rd;
For(i,1,n-1) {
MinMax(l+1,r-1,&ld,&rd);
rs=max(rs,ld-l); rs=max(rs,r-rd);
l=ld; r=rd;
if((r-1)-(l+1)<=rs) {fl=1; break;}
}
if(!fl) rs=max(rs,rd-ld);
return rs;
}
else {
MinMax(l,r,&ld,&rd); l=ld; r=rd; len=(r-l+N-2)/(N-1);
ll lst=l;
for(ll now=l;now<r-1;now+=len) {
MinMax(now+1,min(now+len,r-1),&ld,&rd);
if(~ld) rs=max(rs,ld-lst),lst=rd;
}
rs=max(rs,r-lst);
return rs;
}
}
编译:
g++ -g gap.cpp grader.cpp -o gap
grader.cpp
#include <stdio.h>
#include <stdlib.h> #include "gap.h" static void my_assert(int k){ if (!k) exit(1); } static int subtask_num, N;
static long long A[100001];
static long long call_count; long long findGap(int, int); void MinMax(long long s, long long t, long long *mn, long long *mx)
{
int lo = 1, hi = N, left = N+1, right = 0;
my_assert(s <= t && mn != NULL && mx != NULL);
while (lo <= hi){
int mid = (lo+hi)>>1;
if (A[mid] >= s) hi = mid - 1, left = mid;
else lo = mid + 1;
}
lo = 1, hi = N;
while (lo <= hi){
int mid = (lo+hi)>>1;
if (A[mid] <= t) lo = mid + 1, right = mid;
else hi = mid - 1;
}
if (left > right) *mn = *mx = -1;
else{
*mn = A[left];
*mx = A[right];
}
if (subtask_num == 1) call_count++;
else if (subtask_num == 2) call_count += right-left+2;
} int main()
{
// freopen("gap.in","r",stdin);
// freopen("gap.out","w",stdout);
FILE *in = stdin, *out = stdout;
my_assert(2 == fscanf(in, "%d%d", &subtask_num, &N));
my_assert(1 <= subtask_num && subtask_num <= 2);
my_assert(2 <= N && N <= 100000);
for (int i=1;i<=N;i++) my_assert(1 == fscanf(in, "%lld", A+i));
for (int i=1;i<N;i++) my_assert(A[i] < A[i+1]);
fprintf(out, "%lld\n", findGap(subtask_num, N));
fprintf(out, "%lld\n", call_count);
}
gap.h
void MinMax(long long, long long, long long*, long long*);
交互题(apio2016Gap)的更多相关文章
- 交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]
交互题就是程序与电脑代码的交互. 比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数. 还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互 ...
- CF1114E Arithmetic Progression(交互题,二分,随机算法)
既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...
- Codeforces 1137D - Cooperative Game - [交互题+思维题]
题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...
- Gym - 101375H MaratonIME gets candies 交互题
交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- CF1153E Serval and Snake(交互题)
题目 CF1153E Serval and Snake 很有意思的一道交互题 做法 我们观察到,每次查询一行,当这一行仅包含一端是返回的答案是奇数 根据这个性质查询每一行每一列,我们大体能知道两端的位 ...
- Subway Pursuit (二分)(交互题)
题目来源:codeforces1039B Subway Pursuit 题目大意: 在1到n里有一个运动的点,要求找到这个点,每次可以查询一个区间内有没有这个点,每次这个点往左或者往右移动1到k个位置 ...
随机推荐
- iOS开发之IMP和SEL(方法和类的反射)
1.SEL:类方法的指针,相当于一种编号,区别与IMP! IMP:函数指针,保存了方法的地址! SEL是通过表取对应关系的IMP,进行方法的调用! 2.获取SEL和IMP方法和调用: SEL meth ...
- java笔试之求最小公倍数
正整数A和正整数B 的最小公倍数是指 能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数. package test; import java.util.Scanner; publ ...
- Activiti流程图部署及流程图部分操作
流程图部署有两种方式,一种是通过classpath,另一种是通过zip文件 通过classpath方式如下 public void deploymentProcessDefinition_classp ...
- 同一个局域网内,使用 java 从服务器共享文件夹中复制文件到本地。
1 引用jar 包 <dependency> <groupId>org.samba.jcifs</groupId> <artifactId>jcifs& ...
- sql 递归查询,查出所有子节点
with t as ( select b.* from Base_Department b where ParentId = 'cce4152c-3483-4334-b68d-155da627bca0 ...
- html的常用标签详解1
1.<!DOCTYPE html> 文档声明,不算是标签,但是它可是不能少.这玩意是干什么用的呢? 它是向浏览器自报家门的,即告诉浏览器的解析器应该以什么样的文档类型定义(DTD)来解析它 ...
- ac68u、r8500 梅林固件扩展为一个小型 linux 系统
事先刷 merlin 固件 1.安装 Entware 在安装之前,你需要在路由器中插入一个 U 盘,并将其格式化为 Ext3 / Ext4 格式,插上后在 /mnt/ 下应会多个 sda 设备出来 e ...
- [jeecms]获取父栏目下的子栏目名称
[@cms_channel_list parentId='父栏目id'] [#list tag_list as c] <a href="${c.url}">${c.na ...
- WIX、Squarespace、WordPress 三者的优劣分别是什么?
层出不穷的智能建站,模板建站,源码建站,云建站,仿站,各种建站概念都抛洒于红海之中.到底什么样的网站适合自己,什么样的网站值得我们去消费,什么样的网站能长久,是个非常值得思考的问题. 网站建设技术非常 ...
- PAT甲级——A1059 Prime Factors
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...