ARC070

C - Go Home

题目大意:一只袋鼠第i秒可以向左或向右跳i步或者不跳,问从0跳到x的最小时间

就是1,2,3,4...k总和超过x的最小的k,因为如果超过了x的那部分需要减掉的那步我不跳即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int X; void Solve() {
read(X);
int r = 0;
for(int i = 1 ; i <= 100000 ; ++i) {
r += i;
if(r >= X) {
out(i);enter;return;
}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - No Need

大意:若一个数在任意总和大于等于K的子集内被删掉后,该子集的和仍然大于等于K,认为这个数不必要,求不必要的数的个数

发现如果小于这个数的某值是必要的,这个数也一定是必要的,我们做一个背包,如果存在一个值小于K加上这个数是大于等于K的,那么这个数就是必要的,比最小的必要的数还要小的数都是不必要的

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K,f[MAXN];
int a[MAXN];
void Solve() {
read(N);read(K);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
}
sort(a + 1,a + N + 1);
f[0] = 1;
int ans = N;
for(int i = N ; i >= 1 ; --i) {
for(int j = K - 1 ; j >= 0 ; --j) {
if(f[j] && a[i] + j >= K) ans = min(i - 1,ans);
if(j >= a[i]) f[j] |= f[j - a[i]];
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - NarrowRectangles

大意:每段长度为1的纵坐标有一个线段,初始坐标\(l[i],r[i]\),线段可以移动,要求相邻两个线段之间有交集,可以在端点,求最小移动距离和

设\(dp[i][x]\)是第i条线段左边的点在x的最小花费,这个函数是一个凹(数学老师读音:wa)函数,每个拐点斜率单调递增1,最左的斜率是-i - 1

每次相当于一个绝对值函数累加上,上一次的函数变成,左边i个点向左移动\(r[i] - l[i]\),右边i个点向右移动\(r[i - 1] - l[i - 1]\)

可以用set维护,然后两个新的拐点都是l[i]

维护函数最小值即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 l[MAXN],r[MAXN];
multiset<int64> Lb,Rb;
int64 c,d[2];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(l[i]);read(r[i]);
}
Lb.insert(l[1]);Rb.insert(l[1]);c = 0;
for(int i = 2 ; i <= N ; ++i) {
d[0] -= r[i] - l[i];d[1] += r[i - 1] - l[i - 1];
int64 a = *(--Lb.end()) + d[0],b = *(Rb.begin()) + d[1];
if(l[i] < a) {
c += abs(a - l[i]);
Lb.erase(Lb.find(a - d[0]));Rb.insert(a - d[1]);
Lb.insert(l[i] - d[0]);Lb.insert(l[i] - d[0]);
}
else if(l[i] > b){
c += abs(b - l[i]);
Rb.erase(Rb.find(b - d[1]));Lb.insert(b - d[0]);
Rb.insert(l[i] - d[1]);Rb.insert(l[i] - d[1]);
}
else {
Lb.insert(l[i] - d[0]);Rb.insert(l[i] - d[1]);
}
}
out(c);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - HonestOrUnkind

如果\(A <= B\),从B中选A个人装成互相都是诚实的人,那么不可能分辨出来

然后如果\(A > B\),如果有一个p认为q是unkind,那么p和q至少有一个unkind,同时忽略p,q,那么剩下的仍然honest大于unkind

用个栈,问栈顶新加的点是不是unkind,如果是unkind,那么两个一起删除,最后栈顶剩下的点一定是honest,因为栈中至少有一个honest,两两之间回答都是1,一直指向栈顶都是honest

问那个honest的人所有人的身份即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
bool Query(int a,int b) {
putchar('?');space;out(a);space;out(b);enter;
fflush(stdout);
char s[5];
scanf("%s",s + 1);
if(s[1] == 'Y') return 1;
else return 0;
}
int sta[MAXN],top,A,B;
int ans[MAXN];
void Solve() {
read(A);read(B);
if(A <= B) {puts("Impossible");}
else {
for(int i = 0 ; i < A + B ; ++i) {
if(!top) sta[++top] = i;
else {
if(!Query(sta[top],i)) --top;
else sta[++top] = i;
}
}
int h = sta[top]; for(int i = 0 ; i < A + B ; ++i) {
if(Query(h,i)) ans[i] = 1;
else ans[i] = 0;
}
putchar('!');space;
for(int i = 0 ; i < A + B ; ++i) {
out(ans[i]);
}
enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】ARC070的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. 如何更改电脑ip

    首先打开控制面板==>点击网络和internet==>点击网络和共享中心==>点击更改适配器设置==>右键无线连接或宽带连接(视情况而定)==>属性==>双击ipv ...

  2. Go语言 之TCP聊天室

    服务端流程图如下: package main import ( "fmt" "net" ) // 客户端结构体 type Client struct { //用 ...

  3. ROS机器人开发实践学习笔记1

    刚刚开始学习ROS,打算入机器人的坑了,参考教材是<ROS及其人开发实践>胡春旭编著 机械工业出版社 华章科技出品.本来以为可以按照书上的步骤一步步来,但是,too young to si ...

  4. spring boot jpa-java.lang.IllegalArgumentException: Not a managed type异常问题解决方法

    JPA实体类没有被扫描到,导致这样的情况有以下几种可能: 实体类没有加上@Entity注解 对应解决方法在实体类上加上@Entity即可解决问题 没有按照SpringBoot的约定,默认扫描(appl ...

  5. ajax调用c#后端,发现参数没数值

    之前是int的数据,名字是id 后面被改成字符串的数据,名字是encrptedId 因为名字不匹配,导致找不到数值.只需要把js里调用传递的参数名字改一下,或者C#后端,继续保持原来的名字

  6. MySQL中的sys系统数据库是干嘛的

    mysql5.7增加了sys 系统数据库,通过这个库可以快速的了解系统的元数据信息 这个库确实可以方便DBA发现数据库的很多信息,解决性能瓶颈都提供了巨大帮助   这个库在mysql5.7中是默认存在 ...

  7. Vue于React特性对比(四)

    新开了一个vue的项目,从vue单页面框架搭建到单点登录接入都是自己负责搞的.然后准备将这套东西迁移到react上.然后有了这篇文章. 1,reactjs分环境打包明显要比vue更为麻烦 vue修改的 ...

  8. SQL-W3School-基础:SQL SELECT 语句

    ylbtech-SQL-W3School-基础:SQL SELECT 语句 1.返回顶部 1. 本章讲解 SELECT 和 SELECT * 语句. SQL SELECT 语句 SELECT 语句用于 ...

  9. kotlin之注解

    注解是用来代码添加元数据的一种手段,要声明一个 注解,需要在类之前添加annotation修饰符 annotation class demo 注解其他属性,可以通过向注解类添加元注解的方式来指定 @T ...

  10. c++ for_each

    #include<iostream>#include<algorithm>#include<vector>using namespace std; int main ...