link

orz olinr AK Codeforces Round #533 (Div. 2)

中文水平和英文水平都太渣..翻译不准确见谅

T1.给定n<=1000个整数,你需要钦定一个值t,使得每个整数到线段[t-1,t+1]距离和最小,求最小距离,每个数<=100

枚举t

#include <cstdio>
using namespace std; int n, a[1010]; int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int minans = 0x3f3f3f3f, fuck = -233;
for (int ans = 1; ans <= 100; ans++)
{
int cost = 0;
for (int i = 1; i <= n; i++)
{
if (a[i] > ans)
cost += a[i] - ans - 1;
else if (a[i] < ans)
cost += ans - a[i] - 1;
}
if (cost < minans)
{
minans = cost;
fuck = ans;
}
}
printf("%d %d\n", fuck, minans);
return 0;
}

T2.给定长度为n<=1e5的字符串s和一个数k<=1e5,要求求出一个最大的x,使得字符串中出现x个相同的不重叠的子串,每个子串内只含有一种字符

枚举每段连续区间,开桶记录个数 注意循环完毕字符最后还要算下答案(代码里直接多循环了一次处理)

#include <cstdio>
using namespace std; int bucket[30];
char s[200010];
int n, k; int main()
{
scanf("%d%d", &n, &k);
scanf("%s", s);
char lastch = 0;
int len = 0;
for (int i = 0; i == 0 || s[i - 1] != 0; i++)
{
if (s[i] == lastch)
len++;
else
{
if (lastch != 0)
bucket[lastch - 96] += len / k;
len = 1;
lastch = s[i];
}
}
int ans = 0;
for (int i = 1; i <= 26; i++)
if (ans < bucket[i])
ans = bucket[i];
printf("%d\n", ans);
return 0;
}

T3.求长度为n,数组里每个元素在[l,r]之间并且元素和%3=0的数组数量%1e9+7 n<=2e5,l<=r<=1e9

处理出[l,r]内%3=0,1,2的数字数量,然后无脑dp

#include <cstdio>
#include <iostream>
using namespace std; int n, l, r, p = 1000000007;
int cnt[3];
long long f[200010][3]; int main()
{
scanf("%d%d%d", &n, &l, &r), l--;
cnt[0] = (r + 3) / 3 - (l + 3) / 3;
cnt[1] = (r + 2) / 3 - (l + 2) / 3;
cnt[2] = (r + 1) / 3 - (l + 1) / 3;
f[0][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int now = 0; now <= 2; now++)
{
for (int last = 0; last <= 2; last++)
{
int dis = (now - last) % 3;
if (dis < 0) dis += 3;
f[i][now] += f[i - 1][last] * cnt[dis] % p;
f[i][now] %= p;
}
}
}
cout << f[n][0] << endl;
return 0;
}

T4.N*M(N<=1000,M<=1000)的棋盘上Van一个游戏,一共p<=9个人,每个人有个速度si,每次每个人将他棋盘上所有棋子能走<=si步的所有位置都放上棋子,要求不能经过墙和别的玩家的棋子

bfs套bfs?第一层bfs维护每个玩家的等待扩展的棋子队列,第二层bfs在每个玩家扩展棋子时候维护,对第二层bfs扩展到距离为si的位置加入第一层bfs的队列即可(因为只有他们才能继续扩展)

代码略长

#include <bits/stdc++.h>
using namespace std; int n, m, p, s[15];
int mp[1010][1010];
int dis[1010][1010]; int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0}; int main()
{
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
for (int i = 1; i <= n; i++)
mp[i][0] = mp[i][m + 1] = -1;
for (int j = 1; j <= m; j++)
mp[0][j] = mp[n + 1][j] = -1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
char s;
scanf(" %c", &s);
if (s == '#')
mp[i][j] = -1;
if (s >= '1' && s <= '9')
mp[i][j] = s - 48;
}
}
queue<int> qx, qy;
for (int pl = 1; pl <= p; pl++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (mp[i][j] == pl)
{
qx.push(i), qy.push(j);
}
}
}
}
while (!qx.empty())
{
int x = qx.front(), y = qy.front();
qx.pop(), qy.pop();
int col = mp[x][y];
queue<int> qx1, qy1;
dis[x][y] = 0;
qx1.push(x), qy1.push(y);
while (!qx1.empty())
{
int x1 = qx1.front(), y1 = qy1.front();
qx1.pop(), qy1.pop();
for (int d = 0; d < 4; d++)
{
int nx = x1 + dx[d], ny = y1 + dy[d];
if (mp[nx][ny] != 0) continue;
mp[nx][ny] = col;
dis[nx][ny] = dis[x1][y1] + 1;
if (dis[nx][ny] == s[col])
{
qx.push(nx), qy.push(ny);
}
else
qx1.push(nx), qy1.push(ny);
}
}
}
int ans[13];
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (mp[i][j] > 0)
ans[mp[i][j]]++;
for (int i = 1; i <= p; i++)
printf("%d ", ans[i]);
return 0;
}

做题时候变量名写错了WA了一发。。。

T5.你有一个长度为n(n<=1e5)的事件序列,包含两种事件:1.你可以修改你的社交账户名(修改为你的m个朋友之一 m<=40)2.朋友s访问你的社交账户。如果一个朋友是高兴的,当且仅当每次他访问你时候你的社交用户名都是他的名字。最大化高兴的朋友的数量

将两个事件1之间的所有事件2定义为一个区间,那么这个区间内所有朋友是互斥的,即这些朋友最多有一个是高兴的,那么我们可以构建无向图,每个区间内所有朋友两两连边,最后求最大独立集,可以转化为最大团(其实他俩差不多)

由于m<=40,所以不能枚举集合,官方题解给出了meet in the middle做法,不过这种最大团都可以被随机序列怒艹。。。

#include <bits/stdc++.h>
using namespace std; bool vis[50][50];
int n, tot;
map<string, int> id; bool in[50];
int seq[50]; bool valid(int x)
{
for (int j = 1; j <= n; j++)
if (in[j] == true && vis[j][x] == true) return false;
return true;
} int work()
{
int cnt = 0;
memset(in, 0, sizeof(in));
for (int i = 1; i <= n; i++)
if (valid(seq[i])) in[seq[i]] = true, cnt++;
return cnt;
} void clean()
{
for (int i = 1; i <= n; i++)
if (in[i] == true)
for (int j = 1; j <= n; j++)
if (in[j] == true)
vis[i][j] = true;
memset(in, 0, sizeof(in));
} int main()
{
int cnt;
srand(time(0));
scanf("%d%d", &cnt, &n);
for (int i = 1; i <= cnt; i++)
{
int opd;
scanf("%d", &opd);
if (opd == 1) clean();
else
{
string name;
cin >> name;
if (id.count(name) == false) id[name] = ++tot;
in[id[name]] = true;
}
}
clean();
for (int i = 1; i <= n; i++) seq[i] = i;
int ans = 0, t = 100000;
while (clock() / (double)CLOCKS_PER_SEC <= 1.95)
{
random_shuffle(seq + 1, seq + 1 + n);
ans = max(ans, work());
}
printf("%d\n", ans);
return 0;
}

学校太操蛋,9点55放学,10点10分睡觉,没时间打CF

这次终于有个时间合适的比赛了

第一次打CF,网太卡没hack,最后rating就涨了201,感觉一般般,还是因为自己太菜

前40分钟之内切掉了前4题,然后第五题题意没读懂,问出题人,出题人给回了句原题中的话,给一个词加了粗,然后懂了,懂了后转化出最大团的模型,就是不会做

忘了有个东西叫meet in the middle,也忘了有个东西叫随机化,这就非常cd了

由于学校太操蛋,以后在线打CF的机会肯定不多

打CF主要是练手速和一遍A,毕竟一遍不A扣50分也很恶心的。。。比如说这次B和D都没一遍A

Codeforces Round #533 (Div. 2)题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

随机推荐

  1. __align(num) 分析

    这几天用2440读写SD卡(FAT32文件系统),定义了个文件信息的数据结构里边数据类型有unsigned char, unsigned int, unsigned long几种,在从SD卡上读取数据 ...

  2. linux命令-du查看占用磁盘空间大小

    格式 df -h 查看磁盘分区情况 du /etc 目录文件大小都列出来 单位是k最后一行是总和 du -m 单位是m 小于1m写成1m du -h 单位人性化显示k/m du -sh /etc 查看 ...

  3. DAY14-前端之Bootstrap框架

    Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序而设计的一套前端工具包. 它支持响应式布局,并且 ...

  4. 获取百度搜索结果的真实url以及摘要和时间

    利用requests库和bs4实现,demo如下: #coding:utf- import requests from bs4 import BeautifulSoup import bs4 impo ...

  5. css背景图片位置:background的position(转)

    css背景图片位置:background的position   position的两个参数:水平方向的位置,垂直方向的位置----------该位置是指背景图片相对于前景对象的 1.backgroun ...

  6. css知多少(8)——float上篇(转)

    1. 引言 对于我们所有的web前端开发人员,float是或者曾经一度是你最熟悉的陌生人——你离不开它,却整天承受着它所带给你的各种痛苦,你以为它很简单就那么一点知识,但却驾驭不了它各种奇怪的现象. ...

  7. 2018网络预选赛 徐州G 线段树

    线段树,假设求(x1,y1)点的贡献,就找所有比该点出现时间晚,且x坐标大于x1的点中y最大的,贡献就是Y-y1,由于题目条件限制,不可能有x坐标大于(x1,y1)且y坐标大于y1的点,所以贡献肯定为 ...

  8. 使用Get进行Http通信

    --------------siwuxie095 有道翻译官网:http://fanyi.youdao.com/ 找到官网页面下方的 有道翻译API,选择 调用数据接口,申请一个 key (申请内容可 ...

  9. 最短路径Dijkstar算法和Floyd算法详解(c语言版)

    博客转载自:https://blog.csdn.net/crescent__moon/article/details/16986765 先说说Dijkstra吧,这种算法只能求单源最短路径,那么什么是 ...

  10. NETTY4中的BYTEBUF 内存管理

    转 http://iteches.com/archives/65193 Netty4带来一个与众不同的特点是其ByteBuf的重现实现,老实说,java.nio.ByteBuf是我用得很不爽的一个AP ...