//yy:拒绝转载!!!

悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~

//yy:可是我不会斗地主吖(〃'▽'〃)

~~~那就听两遍小苹果嘛~~~

五一假期除了花时间建模,就抽空把最近没做的CF题补了点。。毕竟明天开始又要继续上好多课呐。。。Yes, I can!(ง •_•)ง……(I can Huá shuǐ~~)

codeforces 803 A. Maximal Binary Matrix   【简单构造】

题意:n行和n列填充零矩阵。 您要将k个1放在其中,使得得到的矩阵相对于主对角线(从左上角到右下角的对角线)是对称的,并且是词典上最大的。如果不存在这样的矩阵,则输出-1。
例如这样的:

Input

3    6

Output

1 1 1
1 1 0
1 0 0

#include<cstdio>
#include<cstring>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
int n, k;
int a[105][105];
int main() {int i, j;scanf("%d%d", &n, &k);CLR(a, 0);if(k > n*n) {printf("-1\n"); return 0;}for(i = 0; i < n; ++i) {if(k) {a[i][i] = 1; k--;}for(j = i+1; j < n; ++j) {if(k >= 2) {a[i][j] = a[j][i] = 1;k -= 2;}}}for(i = 0; i < n; ++i){for(j = 0; j < n-1; ++j) {printf("%d ", a[i][j]);}printf("%d\n", a[i][j]);}return 0;
}

codeforces 803 B. Distances to Zero   【暴力】

题意:给出整数数组a0,a1,...,an-1的数组。对于每个元素,找到其和最近的零的距离(对于等于零的元素)。 给定数组中至少有一个零元素。

题解:暴力,顺的和逆的分别找最近距离并更新

//yy:那天比赛时做完这题就睡觉了orz

#include<cstdio>
#include<cstring>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const int inf = 0x3f3f3f3f;
int n, k;
int a[N], b[N], c[N];
int main() {int i, j;int cnt = 0;scanf("%d", &n);CLR(c, inf);for(i = 0; i < n; ++i) {scanf("%d", &a[i]);if(a[i]==0) {b[cnt++] = i;c[i] = 0;}}for(i = j = 0; i < cnt && j <n; ++i) {for(; j < b[i]; ++j) {c[j] = min(b[i]-j, c[j]);}}for(i = cnt-1, j = n - 1; i >= 0 && j >= 0; --i) {for(; j > b[i]; --j) {c[j] = min(c[j], j-b[i]);}}for(i = 0; i < n-1; ++i)printf("%d ", c[i]);printf("%d\n", c[n-1]);return 0;
}

codeforces 803 C. Maximal GCD

题意:已知正整数n。 你要创建k个正数a1,a2,...,ak(严格增加的序列),它们的和等于n,最大公因数是最大的。
(序列的最大公约数是这样的数字的最大值,即序列的每个元素都可以被它们整除。)如果没有可能的序列,则输出-1。

题解:

//yy:开始看这题看着数字就头疼,后来补题,补完后心情很好喔ヾ(๑╹◡╹)ノ"

//构造:ma,2*ma,3*ma……(k-1)*ma, n-sum,    sum为前k-1项的和

//高斯算法,sum = (首+尾)/2*项数 = (k-1)*k*ma / 2

//关于求最大公约数ma…     ①n % ma = 0;

  ②  k*(k+1)*ma/2  <= n    =>    k*(k+1)/2 <= n/ma

// 最后一项:  n – sum = n – (k-1)*k*ma/2

//输出为-1的情况:k*(k+1)/2>n或k>2e5

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n, k;
int main() {scanf("%lld%lld", &n, &k);if(k*(k+1)/2 > n || k >= 200000) {printf("-1\n"); return 0;}ll ma = 1;for(ll i = 1; i*i <= n; ++i) {if(n % i == 0) {if(n/i >= k*(k+1)/2) ma = max(ma, i);if(i >= k*(k+1)/2) ma = max(ma, n/i);}}for(ll i = 1; i < k; ++i) {printf("%lld ", i*ma);}printf("%lld\n", n-(k-1)*k*ma/2);return 0;
}

codeforces 803 D. Magazine Ad   【二分】

题意:有空格分隔的非空字母的小写和大写拉丁字母。
有连字符'”-“,他们的位置设置了字词换行点。 单词可以包含多个连字符。(保证没有相邻的空格,没有相邻的连字符。 没有连字符与空格相邻。 在第一个单词和最后一个单词之后,没有空格,没有连字符。)
当单词被包裹时,单词之前的连字符的部分和连字符本身保持在当前行上,并且该单词的下一部分放在下一行上。

也可以在两个单词之间设置换行符,在这种情况下,空格停留在当前行上。

该广告占用行数 ≤ k 行,并且应该具有最小的宽度。 广告的宽度是字符串的最大长度(字母,空格和连字符)。

求广告的最小宽度。

//yy:谷歌翻译,你,值得拥有~

#include<cstdio>
#include<cstring>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = 1e6+5;
int k, len;
char s[N];
int f(int m) {int cnt = 0;//行数int x = 0, last = -1;for(int i = 0; i < len; ++i) {if(s[i] == ' ' || s[i] == '-')last = i;//词尾标记if(i == len-1) last = i;x++;if(x >= m) {cnt++; x = i-last;}if(x >= m) return 0;}if(x) cnt++;return cnt <= k;
}
int main() {scanf("%d ", &k);gets(s);len = strlen(s);int l = 0, r = len;while(l < r) {int mid = (l+r)>>1;if(f(mid)) r = mid;else l = mid + 1;}printf("%d\n", l);return 0;
}

这一套题后面补不动了orz,因为看着下一题标签是DP就很烦不想看了。。。

~~~~~~~~~~~~~~~~_(:з」∠)_我的床需要我~~~~~~~~~~~~~~~

codeforces 801 A. Vicious Keyboard   【暴力】

题意:给一串字符,求“VK”出现的最多次数,允许最多修改一个字符

题解:暴力,直接用string的find查找,很方便哦~

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
string s;
int main() {cin >> s;int i = 0, cnt = 0;int len = s.size();while((i = s.find("VK")) != -1) {s[i] = s[i+1] = '.';cnt++;}if(s.find("VV") != -1 ||s.find("KK") != -1)cnt++;printf("%d\n", cnt);return 0;
}

不用find的话,就这样暴力吧。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
string s;
int main() {cin >> s;int i, cnt = 0;int len = s.size();s += 'a';int f = 0;for(i = 0; i < len-1; ++i) {if(s[i] == 'V' && s[i+1] == 'K') {cnt++; i++;continue;}if(f) continue;if(s[i] == 'V' && s[i+1] == 'V' && s[i+2] != 'K') f = 1;else if(s[i] == 'K' && s[i+1] == 'K') f = 1;}printf("%d\n", cnt+(f==1));return 0;
}

codeforces 801 B. Valued Keys   【水】

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 105;
char a[N], b[N];
int main() {scanf("%s %s", a, b);int f = 0;int len = strlen(a);for(int i = 0; i < len; ++i)if(a[i] < b[i]) {f = 1;break;}if(f) puts("-1");else puts(b);return 0;
}

~~~~~~~~~~~~~~~~~~~(:[___] 露眼睡~~~~~~~~~~~~~~~~~

codeforces 798 A. Mike and palindrome  【水】

题意:改变一个字符能否使字符串变为回文串

//yy:第一遍读题不仔细,以为不改变字符也可以,结果…我,我,wa~

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 20;
char a[N];
int main() {scanf("%s", a);int len = strlen(a);int cnt = 0;for(int i = 0; i < len/2; ++i) {if(a[i] != a[len-1-i])cnt++;}if(cnt > 1 || !cnt && len % 2 == 0) puts("NO");else puts("YES");return 0;
}

codeforces 798 B. Mike and strings    【暴力】

题意:给n个字符串,每次可以把一个字符串的第一个字母移到最后,问最少移动几次可以使n个字符串完全相等。

题解:暴力,每次选定一个字符串作为最终结果,把要移动的字符串复制一遍,再find很方便哦~

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 55;
string a[N], b[N];
int main() {int n, i, j;scanf("%d", &n);for(int i = 0; i < n; ++i) {cin >> a[i];b[i] = a[i] + a[i];}int cnt = 0, mi = inf, x = 0;for(i = 0; i < n; ++i) {cnt = 0;for(j = 0; j < n; ++j) {if((x = b[j].find(a[i])) == -1) {puts("-1"); return 0;}cnt += x;}mi = min(mi, cnt);}printf("%d\n", mi);return 0;
}

codeforces 798 C. Mike and gcd problem

题意:每次可以删除 ai, ai + 1 然后把 ai - ai + 1, ai + ai + 1放回原位,求最小次数使得数组所有数的最大公约数大于1

题解:把所有奇数改成偶数即可。。。我居然没想到orz

连续两个奇数改一次即可,一个奇数一个偶数要改两次

//yy:其实一开始我还是有疑问的,题目说gcd(0,2)=2,0怎么可以求最大公约数啊(-_-)ゞ

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll a[N];
int main() {int n, i, j;scanf("%d", &n);ll t = 0;for(i = 0; i < n; ++i) {scanf("%lld", &a[i]);t = gcd(t, a[i]);}if(t > 1) {puts("YES\n0\n"); return 0;}int ans = 0;for(i = 0; i < n; i++) {if(a[i] % 2 == 1) {ans++;if(a[++i] % 2 == 0) ans++;}}printf("YES\n%d\n", ans);return 0;
}

codeforces 798 D. Mike and distribution

题意:让你选择k 个数 组成序列:P = [p1, p2, ..., pk] ( 1 ≤ pi ≤ n , 1 ≤ i ≤  )并且序列中的元素都不同。满足: 2·(ap1 + ... + apk) 大于A数组的所有元素之和,2·(bp1 + ... + bpk) 大于B数组所有元素之和。并且k≤

题解:第一遍做的时候,我先将下标以A的大小顺序来排序,若n为奇数,则k=n/2+1,先选取第一个下标,再两个两个的根据B数组的数的大小来选取下标;若n为偶数,则k = n/2,再两个两个选取下标,但是错了哦WA,因为题目说了是大于元素之和,我这样写是大于等于。。。正解:排序照旧,k直接取n/2+1,然后就没有然后了,详见代码。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 1e5+5;
int a[N], b[N], p[N];
bool cmp(int x, int y) {return a[x] > a[y];
}
int main() {int n, i, j;scanf("%d", &n);for(i = 0; i < n; ++i) scanf("%d", &a[i]);for(i = 0; i < n; ++i) scanf("%d", &b[i]);for(i = 0; i < n; ++i) p[i] = i; //下标sort(p, p+n, cmp);printf("%d\n%d ", n/2+1, p[0]+1);for(i = 1; i < n-1; i += 2) {if(b[p[i]] > b[p[i+1]]) printf("%d ", p[i]+1);else printf("%d ", p[i+1]+1);}if(i == n-1) printf("%d", p[n-1]+1);return 0;
}

~~~~~~~~~~~~~~~(|3[____] 睡的很死..~~~~~~~~~~~~~~~

~~~补西电校赛一道水题:

xidian 1200: Hanoi Tower – SetariaViridis   【快速幂】

普通的汉诺塔是2^n-1,这里乘个2就行了。为什么呢为什么呢(O_O)?

#include<cstdio>
#include<cstring>
#include<algorithm>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
ll p = 2097151;
ll pow_mod(ll a, ll b) {ll r = 1;while(b) {if(b&1) r = (r*a)%p;a = (a*a)%p;b >>= 1;}return r;
}
int main() {ll n;while(~scanf("%lld", &n))printf("%lld\n", ((pow_mod(2,n)-1)*2)%p);return 0;
}

~~~~~~~马拉松24

51nod 1804 小C的多边形

//yy:题目今天还没挂出来,直接贴上房教的代码~( ̄▽ ̄)~*

#include<stdio.h>
using namespace std;
#define mem(a,b); memset(a,b,sizeof(a));
#define scan(a);  scanf("%d",&a);
typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6+10;
int main()
{int n;scan(n);ll a = ll(n)*(n-1)/2*3;if(a%(n-1)) return 0*printf("0\n");int ans=a/(n-1);for(int i=1;i<=n-1;i++){if(i>1) printf(" ");printf("%d",i);}printf("\n");int pre = ans - n;printf("%d",pre);for(int i=1;i<n-1;i++){printf(" ");printf("%d",ans-i-pre);pre = ans-i-pre;}printf("\n");return 0;
}

//yy:写完博客刚好熄灯。◕ᴗ◕。

转载于:https://www.cnblogs.com/GraceSkyer/p/6793779.html

4.30-5.1cf补题相关推荐

  1. 2018-2019赛季多校联合新生训练赛第五场补题与题解(中石油)

    总结:这场比赛比的我很迷啊,刚开始一个多小时就a了七道题,然后往后怎么做都做不出来题了...我也不知道为什么,反正比赛途中因为一个题做不出来直接自闭(疯狂锤头),通过这场比赛我发现一件事情:打比赛的时 ...

  2. 2019ICPC上海区域赛 补题(12/13) 总结

    前言: 个人的 ICPCICPCICPC 第一站,还是值得记录一下的(虽然咕到现在才记录),总体而言体验很不错,比赛兼旅游.这套题总体印象就是树树树图,作为队里数据结构兼图论选手,这次也确实写了大部分 ...

  3. 2019寒假集训第五场(新生场)中石油补题和题解

    这场比赛本来我都出去了,然后看到老师发消息又回来了= = 然后做着做着正好mhr大佬在外面有一些事情突然没法比赛,于是就帮他交了两道题看看对不对,便于之后补题,然后还真都对了,下面是题目和解析: 问题 ...

  4. 2022.11.17补题祭

    前言: 考完期中考试了!!生物逆袭了!!全年级前十(可能是因为题目太简单我比较细心吧)但还是错了一些不该错的题目......(生物惨痛87分) 感觉这次期中考试情况良好,在会做难题的同时,也要好好巩固 ...

  5. 2021杭电多校补题——第一场

    2021杭电多校补题--第一场 文章目录 Mod, Or and Everything Rocket land(待补) Puzzle loop(待补) Another thief in a Shop( ...

  6. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  7. pta 绍兴文理学院元培学院2022/3/11 补题

    比赛对了6/10,这个比赛相对简单吧. 补题 小杨在心灵走廊中闯入603号房间时,一张巨大的星图展现在他的面前,脚边也多了m支笔.星图上每颗星都代表着一个交点,每两颗星之间可能有线相连,每条线除了端点 ...

  8. 暑假搜索专题1(搜索)补题

    A - Fox And Two Dots(CF510B) 最后突然发现有个特判,为此t了好几发 #include<stdio.h> #include<string.h> #in ...

  9. 2022.1.18(一测补题,树的遍历题目,并查集)

    由于深夜点了外卖要1:50才到 闲着没事就补一下题目! 题目如下: 题目描述 In one one-dimensional world there are nn platforms. Platform ...

最新文章

  1. Windows驱动开发学习笔记(五)—— SSDT HOOK
  2. 算盘与电子计算机的区别之一是,算盘与电子计算机的区别之一是算盘没有存储能力...
  3. IOS用户界面的新视觉比例
  4. GraphQL query的schema校验
  5. 复习上学期的HTML CSS(1)
  6. MAYA建模桌面一角_maya怎么建模逼真的学生书桌书桌桌面?
  7. 看过这五条,再离职!
  8. LeetCode 257. Binary Tree Paths (二叉树路径)
  9. 云原生的本质_什么是云原生?云原生和传统软件有什么区别?有什么特征
  10. docker中linux用户名密码,linuxea:尽可能不在docker镜像中嵌入配置或者密码
  11. Linux下gcc/g++、make和cmake的区别
  12. 通过Windows Live Writer发布日志到各大博客
  13. 视频软件会声会影支持哪些视频格式?
  14. 【HDOJ】1667 The Rotation Game
  15. 王庆的边缘计算(第四章)
  16. u盘安全删除 linux,怎么安全删除U盘
  17. 使用 net C 发送邮件(带成功案例)
  18. 红外真空离心浓缩仪ZLNS-II
  19. 精选腾讯出品的 16 款小程序
  20. 【MacOS】java环境配置

热门文章

  1. poi读取excel模板,并填充数据
  2. webBrowser中打不开http://subway.simba.taobao.com页面解决办法
  3. WOW6432Node真身 注册表
  4. 谷歌面试 扔鸡蛋_如何解决Google招聘人员关于从建筑物中扔鸡蛋的难题
  5. VR全景的制作与拍摄
  6. 基于java下的Springboot框架实现幼儿园管理系统
  7. 【代码随想录算法练习】| DAY01 | JavaScript | 数组理论基础,704. 二分查找,27. 移除元素
  8. than用法总结(基于材料:“老托福听力93篇”)
  9. 解读SOX法案对中国运营商的影响
  10. 关于传智书城QQ邮箱激活问题