A: Adjustment Office

题意:在一个n*n的矩阵,每个格子的的价值为 (x+y), 现在有操作取一行的值,或者一列的值之后输出这个和, 并且把这些格子上的值归0。

题解:模拟, 分成xy轴就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("adjustment.in","r",stdin); freopen("adjustment.out","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e6 + ;
LL sumx, sumy;
int cntx, cnty;
int visx[N], visy[N];
char op[];
int p;
int main(){
Fopen;
int n, q;
scanf("%d%d", &n, &q);
sumx = sumy = (1ll+n)*n / ;
cntx = cnty = n;
while(q--){
scanf("%s%d", op, &p);
if(op[] == 'R'){
if(visx[p])
puts("");
else{
visx[p] = ;
LL ans = 1ll * cnty * p + sumy;
sumx -= p;
--cntx;
printf("%lld\n", ans);
}
}
else {
if(visy[p])
puts("");
else{
visy[p] = ;
LL ans = 1ll * cntx * p + sumx;
sumy -= p;
--cnty;
printf("%lld\n", ans);
}
}
}
return ;
}

D:题解传送门

E:Easy Problemset

题意:有n组题目,每组题目有pi个题目,然后每个题目有一个[0, 49]的难度, 现在轮着选这些题, 当入选题目的总难度小于等于当天题目的时候,就把这个题目加入入选题目, 如果一组题目用完了就用50的题目去填充,当选完了所有题目之后还没有满足条件,就用难度50的题目填充剩下的。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("easy.in","r",stdin); freopen("easy.out","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int p[][];
int a[];
int main(){
Fopen;
int n, k;
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i){
scanf("%d", &a[i]);
for(int j = ; j <= a[i]; ++j)
scanf("%d", &p[i][j]);
for(int j = a[i]+; j < ; ++j)
p[i][j] = ;
}
int sum = ;
for(int j = ; j < ; ++j){
for(int i = ; i <= n; ++i){
if(sum <= p[i][j]){
sum += p[i][j];
--k;
if(k == ){
printf("%d\n", sum);
return ;
}
} }
}
sum += * k;
printf("%d\n", sum);
return ;
}

F:Froggy Ford

题意:从图的最左边跑到最右边,只能在点(河岸),现在可以新增一个点,问你从最左边跳到最右边,最长跳远最小可以是多少。

题解:我们从左边跑一遍n^2的最短路,然后从右边跑一遍最短路,然后再枚举2个点找最优解就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("froggy.in","r",stdin); freopen("froggy.out","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = ;
double e[N][N];
pll p[N];
int w, n;
inline double cal(pll & p1, pll & p2){
return sqrt(pow(p1.fi-p2.fi, ) + pow(p1.se-p2.se,));
}
double dis[][N];
int vis[N];
void dijkstra(int st,int op){
memset(vis, , sizeof(vis));
for(int i = ; i <= n + ; ++i)
dis[op][i] = e[st][i];
dis[op][st] = ; vis[st] = ;
while(true){
double min1 = INF;
int z = -;
for(int j = ; j <= n+; j++)
if(!vis[j] && min1 > dis[op][j])
z = j, min1 = dis[op][j];
if(z == -) break;
vis[z] = ;
for(int j = ; j <= n; ++j){
dis[op][j] = min(dis[op][j], max(e[z][j], dis[op][z]));
}
}
} int main(){
Fopen;
scanf("%d%d", &w, &n);
for(int i = ; i <= n; ++i)
scanf("%d%d", &p[i].fi, &p[i].se);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j){
e[i][j] = cal(p[i], p[j]);
}
for(int i = ; i <= n; ++i){
e[i][] = e[][i] = p[i].fi;
e[i][n+] = e[n+][i] = w - p[i].fi;
}
e[n+][] = e[][n+] = w;
dijkstra(,);
dijkstra(n+,);
int p1, p2;
double llen = INF;
for(int i = ; i <= n + ; ++i){
for(int j = ; j <= n+; ++j){
double tmp = max3(dis[][i], dis[][j], e[i][j]/2.0);
if(tmp < llen){
llen = tmp;
p1 = i, p2 = j;
}
}
} int ansx, ansy;
if(p1 > p2) swap(p1, p2);
if(p1 == ){
ansx = p[p2].fi;
ansy = p[p2].se*;
}
else if(p2 == n+){
ansx = p[p1].fi + w;
ansy = p[p1].se * ;
}
else {
ansx = p[p1].fi + p[p2].fi;
ansy = p[p1].se + p[p2].se;
}
if(ansx&) printf("%d.5 ", ansx/);
else printf("%d ", ansx/);
if(ansy&) printf("%d.5", ansy/);
else printf("%d", ansy/);
return ;
}

G:Generators

题意:有n个生成序列,现在要你在这n个生成序列每个都找到一个值相加,要求和在不能被k整除的情况下最大。

题解:暴力跑出循环节,找到每个序列的最大值和次大值,最大值和次大值的差不能被k整除,然后把每个序列的最大值相加, 然后如果被k整除,就找一个次小值去替换。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("generators.in","r",stdin); freopen("generators.out","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = ;
int vis[];
int A[N];
int p[N][], v[N][];
int main(){
Fopen;
int n, k, a, b, c, x, m;
scanf("%d%d", &n, &k);
int sum = ;
for(int i = ; i <= n; ++i){
scanf("%d%d%d%d", &x, &a, &b, &c);
m = ;
while(!vis[x]){
A[++m] = x;
vis[x] = ;
x = (a*x + b) % c;
}
for(int j = ; j <= m; ++j){
vis[A[j]] = ;
if(v[i][] <= A[j]){
v[i][] = A[j];
p[i][] = j;
}
}
sum += v[i][];
for(int j = ; j <= m; ++j){
if(v[i][] == A[j]) continue;
if((v[i][]-A[j])%k != && v[i][] <= A[j]){
v[i][] = A[j];
p[i][] = j;
}
}
}
if(sum % k == ){
int tmp = , pos, val = ;
for(int i = ; i <= n; ++i){
if(p[i][] == ) continue;
tmp = sum - v[i][] + v[i][];
if(tmp > val){
val = tmp;
pos = i;
}
}
if(val != ){
sum = val;
p[pos][] = p[pos][];
}
}
if(sum%k == ) puts("-1");
else {
printf("%d\n", sum);
for(int i = ; i <= n; ++i)
printf("%d ", p[i][]-);
} return ;
}

J:Jump 交互题

题意:现在有一个长度为偶的01序列,然后要求你每次输出一个序列,如果这个输出序列的和原序列的相同的位置的个数是 n 或者 n/2 的话会输出这个值否者输出0。

题解:先rand找到一个n/2的,然后就假设第一位值正确的,然后枚举每个位置的变化。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
char s[N];
char ans1[N], ans2[N];
int f = , n, t;
void boom(){
for(int i = ; i < n; ++i) s[i] = '' + ((rand()%));
}
int main(){
srand();
scanf("%d", &n);
s[n] = '\0';
while(){
boom();
puts(s);
cout << flush;
scanf("%d", &f);
if(f == n) return ;
if(f == n/) break;
}
if(f == n/){
ans1[] = s[];
ans2[] = '' + '' - s[];
s[] = '' + '' - s[];
for(int i = , t; i < n; ++i){
s[i] = '' + '' - s[i];
printf("%s\n", s);
cout << flush;
scanf("%d", &t);
if(t == n/) {
ans1[i] = s[i];
ans2[i] = '' + '' - s[i];
}
else {
ans1[i] = '' + '' - s[i];
ans2[i] = s[i];
}
s[i] = '' + '' - s[i];
}
ans1[n] = '\0';
ans2[n] = '\0';
printf("%s\n", ans1);
cout << flush;
scanf("%d", &t);
if(t != n){
printf("%s\n", ans2);
cout << flush;
}
}
return ;
}

K:King’s Inspection

题意:有一幅图 n个点的图,m个单向边, 问能不能从1号点出发,然后绕一圈,经过其他的所有的点一次,然后会到一号点。

题解:因为最多是 n+20条边,我们先判断一下有没有 入度为0 或者 出度为0有就是非法的。

20个多的边 如果都走一遍 也就是 2^20次方 ≈ 1e6, 但是 我们如果遍历其他的链, 那么要1e6 * 1e5 就不行了。

所以我们把这些单链都缩点,缩成一条边,这样在图合法的前提下,我们的图就会很小,就可以爆搜了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("king.in","r",stdin); freopen("king.out","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
vector<int> e[N];
vector<pll> vc[N];
int in[N], out[N], ok[N], vis[N];
int nt[N];
int sta[N];
int n, m, u, v;
void P(int k){
for(int i = ; i <= k; ++i){
printf("%d ", sta[i]);
if(ok[sta[i]]){
int x = nt[sta[i]];
while(x){
printf("%d ", x);
x = nt[x];
}
}
}
printf("");
}
void dfs(int u, int k, int num){
sta[k] = u;
vis[u] = ;
for(int i = ; i < vc[u].size(); ++i){
int v = vc[u][i].fi, ct = vc[u][i].se;
if(vis[v]){
if(v == && num + ct == n){
P(k);
exit();
}
continue;
}
vis[v] = ;
dfs(v, k+, num++ct);
vis[v] = ;
}
}
int main(){
Fopen;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i){
scanf("%d%d", &u, &v);
in[v]++, out[u]++;
e[u].pb(v);
}
for(int i = ; i <= n; ++i){
if(in[i] < || out[i] < ) {
puts("There is no route, Karl!");
return ;
}
ok[i] = (in[i] == && out[i] == );
}
ok[] = ;
for(int i = ; i <= n; ++i){
if(vis[i]) continue;
if(ok[i]){
int to = e[i][], ct = , now = i;
vis[i] = ;
while(ok[to]){
if(vis[to]){
if(to == i) break;
nt[now] = to;
ct += vc[to][].se + ;
to = vc[to][].fi;
}
else {
ct++;
vis[to] = ;
nt[now] = to;
now = to;
to = e[to][];
}
}
vc[i].pb({to,ct});
}
else {
for(int j = ; j < e[i].size(); ++j){
vc[i].pb({e[i][j],});
}
}
}
memset(vis, , sizeof vis);
dfs(, , );
puts("There is no route, Karl!");
return ;
}
/*
10 11
10 8
5 4
9 1
4 3
7 2
2 6
6 5
8 9
1 7
10 3
3 10
*/

L:Landscape Improved

题解:直接模拟就好了,我们可以发现不好同时维护左边的信息,维护右边的信息,所以我们可以把他们分开来处理,最后在把所有的信息合在一起。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
LL h[N], hh[N];
LL m;
int n;
bool check(LL x){
memset(hh, , sizeof hh);
LL s = , r = , l = n-;
for(int i = ; i <= n; ++i){
if(r == i) r = i+, s = ;
while(r <= n && h[r] < x - (r-i)){
s += x - (r-i) - h[r];
r++;
}
// cout << i << ' ' << r << ' ' << s << endl;
if(r > n) hh[i] = INF;
else {
hh[i] = s;
s -= max(0ll, (x-)-h[i+]); s += max(0ll, (r-)-(i+));
// cout << s << endl;
}
}
s = ;
for(int i = n; i >= ; --i){
if(l == i) l = i-, s = ;
while(l >= && h[l] < x - (i-l)){
s += x - (i-l) - h[l];
l--;
}
if(l < ) hh[i] = INF;
else {
hh[i] += s;
s -= max(0ll, (x-)-h[i-]);
s += max(0ll, (i-)-(l+));
}
}
for(int i = ; i <= n; ++i){
hh[i] += max(0ll, x-h[i]);
if(hh[i] <= m) return true;
}
return false;
}
int main(){
freopen("landscape.in","r",stdin);
freopen("landscape.out","w",stdout);
scanf("%d%lld", &n, &m);
LL mx = ;
for(int i = ; i <= n; ++i){
scanf("%lld", &h[i]);
mx = max(mx, h[i]);
} LL l = mx+, r = m + mod;
while(l <= r){
LL mid = l+r >> ;
if(check(mid)) l = mid + ;
else r = mid - ;
}
printf("%lld\n", l-); return ;
}

Gym 100851 题解的更多相关文章

  1. 【二分】NEERC15 L Landscape Improved(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 只要一个格子的 ...

  2. 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: n个序列.每个序列有4个值x,a,b,c,之后按照x=(a*x+b)%c扩展无穷项. 求每个序列各取一个数之后 ...

  3. 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...

  4. 【最短路】NEERC15 F Froggy Ford(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一只青蛙跳过宽为W的河,河中游N个石头,坐标xi,yi,现在往河中间添加一个石头,使得每次跳跃的最大的距离最小 ...

  5. 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...

  6. 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和.C c ...

  7. Gym 100851 Distance on Triangulation

    题意:给你一个N边形, 然后这个n边形有n-3条边,然后询问2点之间的最短路. 题解:分治. 我们可以找到一条边,使得这幅图能分成大小相同的2幅图,那么我们就可以确定那些被分割开的询问的答案是多少了. ...

  8. Gym 101482 题解

    B:Biking Duck 题意:现在有一个人要从(x1,y1)点走到(x2,y2)点, 现在走路的速度为v. 还有骑自行车的速度v2,自行车要从某个自行车站到另一个自行车站,现在我们可以视地图的边界 ...

  9. Gym 101470 题解

    A:Banks 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt&q ...

随机推荐

  1. codeforces 371A K-Periodic Array

    很简单,就是找第i位.i+k位.i+2*k位...........i+m*k位有多少个数字,计算出每个数出现的次数,找到出现最多的数,那么K-Periodic的第K位数肯定是这个了.这样的话需要替换的 ...

  2. Python机器学习·微教程

    Python目前是机器学习领域增长最快速的编程语言之一. 该教程共分为11小节.在这个教程里,你将学会: 如何处理数据集,并构建精确的预测模型 使用Python完成真实的机器学习项目 这是一个非常简洁 ...

  3. UR机器人通信--上位机通信(python)

    一.通信socket socket()函数 Python 中,我们用 socket()函数来创建套接字,语法格式如下: socket.socket([family[, type[, proto]]]) ...

  4. Unbutu在VMWare中挂载共享文件夹

    第一,安装VMTools,步骤自行搜索,安装成功后重启虚拟机. 第二,重启后,在虚拟机管理页面设置共享目录,选择总是启用,开启虚拟机. 第三,在终端进入挂载目录cd /mnt/hgfs/,通过命令su ...

  5. as更新3.0.1的时候的编译异常

  6. 浅谈IDEA集成SSM框架(SpringMVC+Spring+MyBatis)

    前言 学习完MyBatis,Spring,SpringMVC之后,我们需要做的就是将这三者联系起来,Spring实现业务对象管理,Spring MVC负责请求的转发和视图管理, MyBatis作为数据 ...

  7. ubuntu-18.10 虚拟机 配置网络环境

    查询主机系统ip 使用virtualbox 设置网络模式为桥接模式 设置静态 ip 与网关 关闭防火墙 sudo ufw disable

  8. bi-Lstm +CRF 实现命名实体标注

    1. https://blog.csdn.net/buppt/article/details/82227030 (Bilstm+crf中的crf详解,包括是整体架构) 2. 邹博关于CRF的讲解视频 ...

  9. net core天马行空系列:原生DI+AOP实现spring boot注解式编程

    写过spring boot之后,那种无处不在的注解让我非常喜欢,比如属性注入@autowire,配置值注入@value,声明式事物@Transactional等,都非常简洁优雅,那么我就在想,这些在n ...

  10. [系列] go-gin-api 规划目录和参数验证(二)

    目录 概述 规划目录结构 模型绑定和验证 自定义验证器 制定 API 返回结构 源码地址 go-gin-api 系列文章 概述 首先同步下项目概况: 上篇文章分享了,使用 go modules 初始化 ...