比赛入口

B 都说小镇的切糕贵

做法:题意是要求一个字符串中能包含该串出现所有字符的最小长度,是滑动窗口技巧题目的典型例题。
具体滑动窗口实现:
如果左边界遇到 与当前s[i]相同且s[i]之前出现过 的,更新最小窗口长度res = min(res, i-l+1);
如果左边界遇到 与当前s[i]相同且s[i]之前未出现过 的,把flag置为1,处理完l后强制更新res = i - l + 1。

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
int main() {fioint n; cin >> n;string s; cin >> s;int len = s.size();unordered_map<char, int> vis;vis.clear();int l = 0, res = n;for(int i = 0; i < len; ++i) {int flag = 0;if(!vis[s[i]]) flag = 1; //与当前s[i]相同且s[i]之前未出现过vis[s[i]]++;while(vis[s[l]] > 1) {vis[s[l]]--; l++;}if(flag) res = i - l + 1;else res = min(res, i - l + 1);}printf("%d\n", res);return 0;
}

C Guard the empire

做法:题意是要求最少需要多少个半径为r的圆(圆心都在x坐标上),能覆盖住n个给定坐标的点。做法就是找到每个圆能够取到的圆心位置的区间,再贪心找最少有多少个点能将所有区间都部分覆盖。

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
const int N = 1003;
struct Qujian {int l, r;bool operator < (const Qujian &c) const {if(l != c.l) return l < c.l;return r < c.r;}
}qj[N];
double toQj(double y, double r) {return sqrt(r*r - y*y);
}
int main() {int n, c = 0;double r;while(scanf("%d%lf", &n, &r), n || r) {double x, y, cha;int flag = 1;for(int i = 0; i < n; ++i) {scanf("%lf%lf", &x, &y);if(y > r) {   //如果超出了圆能表示的范围flag = 0; continue;}cha = toQj(y, r);//找出可以覆盖住该点的圆心范围qj[i].l = x - cha; qj[i].r = x + cha;}if(!flag) {printf("Case %d: %d\n", ++c, -1);} else {//贪心找能覆盖住所有点的圆个数sort(qj, qj+n);double mid = qj[0].r;int res = 1;for(int i = 1; i < n; ++i) {if(qj[i].l > mid) {mid = qj[i].r; res++;} else if (qj[i].r < mid) {mid = qj[i].r;}}printf("Case %d: %d\n", ++c, res);}}return 0;
}

H Magic necklace

做法:有一串标号1~n的数字,要求每个数字不相邻的方案数,因为数字很小,直接上暴力预处理即可,这里用了next_permutation函数。

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
int res[15], mid[15], n;
int check(int n) {for(int i = 1; i <= n; ++i) {if(fabs(mid[i+1] - mid[i]) == 1) return 0;}return 1;
}
int main() {//暴力预处理res[1] = 1; res[2] = 0;for(int i = 3; i <= 11; ++i) {for(int j = 1; j <= i; ++j) mid[j] = j;mid[i+1] = mid[1];while(next_permutation(mid+2, mid+i+1)) {if(check(i)) res[i]++;}res[i] = res[i] / 2;}int t; scanf("%d", &t);while(t--) {scanf("%d", &n);printf("%d\n", res[n]);}return 0;
}

I 恋爱之子

做法:一些线段,所有相交的线段成为一个集合,要求有多少个集合,几何板子——判断两条线段是否相交,再用并查集即可。

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
const int N = 4003;
struct Dian {  //点LL x, y;
};
struct Xian {  //线Dian s, e;
} xian[N];
double mul(Dian a, Dian b, Dian c) {  //向量叉积return ((double)(b.x-a.x) * (c.y-a.y) - (double)(c.x-a.x) * (b.y-a.y));
}
int isJiao(Xian a, Xian b) {  //判断两个线段是否相交if( min(a.s.x, a.e.x) <= max(b.s.x, b.e.x) &&max(a.s.x, a.e.x) >= min(b.s.x, b.e.x) &&min(a.s.y, a.e.y) <= max(b.s.y, b.e.y) &&max(a.s.y, a.e.y) >= min(b.s.y, b.e.y) &&mul(b.s, a.s, b.e) * mul(b.s, b.e, a.e) >= 0 &&mul(a.s, b.s, a.e) * mul(a.s, a.e, b.e) >= 0 )return 1;return 0;
}
int a[N];
int Find(int x) {return a[x] == x ? x : a[x] = Find(a[x]);
}
void Merge(int x, int y) {int fx = Find(x), fy = Find(y);if(fx != fy) {a[fy] = fx;}
}
int main() {int n; scanf("%d", &n);for(int i = 0; i < n; ++i) {scanf("%lld%lld%lld%lld", &xian[i].s.x, &xian[i].s.y, &xian[i].e.x, &xian[i].e.y);a[i] = i;}for(int i = 0; i < n - 1; ++i) {for(int j = i + 1; j < n; ++j) {if(isJiao(xian[i], xian[j])) Merge(i, j);}}int res = 0;for(int i = 0; i < n; ++i) {if(a[i] == i) res++;}printf("%d\n", res);return 0;
}

K 集训队的依赖关系

做法:由一棵无根树建立超级源点0,再对这棵树进行树形dp,现在还是对树形dp很迷,等彻底学会再来写一篇树形dp专题,咕咕咕~

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
const int N = 5100;
int n, m, S;
int val[N], in[N], cost[N];
LL now[N], dp[N][N];
vector<int> ve[N];
void dfs(int u) {for(int i = S; i >= 0; --i) {if(i >= cost[u]) dp[u][i] = dp[u][i-cost[u]] + val[u];else dp[u][i] = -1e18;}for(int v : ve[u]) {for(int i = 0; i <= S; ++i) dp[v][i] = dp[u][i];dfs(v);for(int i = 0; i <= S; ++i) dp[u][i] = max(dp[u][i], dp[v][i]);}
}
int main() {int u, v;read(n); read(S); read(m);for(int i = 1; i <= n; ++i) read(val[i]);for(int i = 1; i <= n; ++i) read(cost[i]);for(int i = 0; i < m; ++i) {read(u); read(v);ve[v].push_back(u);in[u]++;}for(int i = 1; i <= n; ++i) {if(in[i]) continue;ve[0].push_back(i);}dfs(0);LL ans = 0;for(int i = 0; i <= S; ++i) ans = max(ans, dp[0][i]);printf("%lld\n", ans);return 0;
}

L 金牌厨师HiLin与HJGG

做法:题意就是有一个大矩阵,要求选一个最小的m,使得m*m矩阵中所有数字之和大于等于k,用到二位前缀和。

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;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;
}
const int N = 2003;
int a[N][N];
LL sum[N][N];
int n, k;
int solve(int x, int y, int nn) {x--; y--;if(sum[x+nn][y+nn] - sum[x][y+nn] - sum[x+nn][y] + sum[x][y] >= k) return 1;return 0;
}
int main() {read(n); read(k);//二维前缀和预处理for(int i = 1; i <= n; ++i) {for(int j = 1; j <= n; ++j) {read(a[i][j]);sum[i][j] = a[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];}}//暴力枚举每个m,加剪枝LL ans = n;for(int i = 1; i <= n; ++i) {for(int j = 1; j <= n; ++j) {for(int nn = ans; nn >= 1 && nn <= n-i+1 && nn <= n-j+1; --nn) {if(solve(i, j, nn)) {ans = nn;} else break;}}}if(sum[n][n] < k) puts("I'm a Gold Chef!");else printf("%lld\n", ans);return 0;
}

补题:西南民族大学第十一届程序设计竞赛(同步赛)相关推荐

  1. 西南民族大学第十一届程序设计竞赛(同步赛)(回顾补题)

    先贴一波官方题解 这次比赛一道贪心原题,一道矩阵快速幂模板题,总体难度一般,不会的知识点 尺取,树形依赖背包 大模拟没写出来,可惜可惜 A 川川教练的困惑 直接暴力模拟 #include<bit ...

  2. 江西财经大学第二届程序设计竞赛同步赛 H大时钟 (扩展欧几里得)

    链接:https://ac.nowcoder.com/acm/contest/635/H 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  3. (江西财经大学第二届程序设计竞赛同步赛)E-是不是复读机

    E-是不是复读机 题目描述: 在复读纪元2140年,复读机(们)已经放弃了如下所示的低级复读方式: "哟,小伙汁,想不到你也是个复读机" "哟,小伙汁,想不到你也是个复读 ...

  4. 江西财经大学第二届程序设计竞赛同步赛----E-是不是复读机

    首先发出题目链接: 链接:https://ac.nowcoder.com/acm/contest/635/E 来源:牛客网 题目如下: 看完题目之后就有两个问题摆在面前: (1)题目输入的是一串英文, ...

  5. 牛客练习-哈尔滨理工大学21级新生程序设计竞赛(同步赛)

    比赛链接:哈尔滨理工大学21级新生程序设计竞赛(同步赛) 文章目录 前言 正文 A.考试周破防 B.咖啡店 C.kiki和bob玩取石子 D.猴王kiki分桃 E.很二的拆分 F.构造字符串 G.信号 ...

  6. “科林明伦杯”哈尔滨理工大学第十届程序设计竞赛(同步赛) 题解

    "科林明伦杯"哈尔滨理工大学第十届程序设计竞赛(同步赛) 题解 萌新又来写题解啦 原题链接 B 减成一 题意:存在n个数,每次操作可以任选一个区间使得区间内的所有数字减一.问最少多 ...

  7. 2021年广东工业大学第11届腾讯杯新生程序设计竞赛(同步赛)错题笔记

    目录: 题目链接 A 比比谁更大 B 过生日 D 机器人 G 拼牛牛 I 史莱姆 J 水题 K 烧烤丝瓜 L 歪脖子树下的灯 题目链接 A 比比谁更大 题目描述 在一个夜黑风高的晚上,牛哥哥吃完心爱的 ...

  8. 【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】 小乐乐算数字(水题,快速幂,lowbit)

    题干: 小乐乐最喜欢玩数字了. 小乐乐最近迷上了2这个整数,他觉得2的幂是一种非常可爱的数字. 小乐乐想知道整数x的最大的 2的幂 (2^y)的因子. y为整数. 输入描述: 输入整数x.(1< ...

  9. 【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐切割方块(思维,水题)

    题干: 小乐乐的作业本是2n*2n的方格本. 某天小乐乐的童鞋,想要考验一下小乐乐. 他将小乐乐的一张方格纸中的某个格子(x,y)涂成黑色, 小乐乐能否在将4*4的方格本沿着方格边缘且切割线与黑色方格 ...

最新文章

  1. 记一次MySQL AUTO_INCREMENT的故障
  2. (chap4 Http状态码) 5XX
  3. 数据加密和OpenSSL
  4. [转] PHP在不同页面之间传值的三种常见方式
  5. SRAM(静态随机存储器)
  6. es查询大文本效率_进一步提高Elasticsearch的检索效率
  7. numpy二维数组改变某些数_机器学习:Python常用库——Numpy库
  8. 连通子图什么意思_一道物理竞赛题揭开“希罗喷泉”的神秘面纱,到底什么物理原理?...
  9. python找不到csv文件路径_无法识别csv的构造文件路径。但文件是
  10. Vue项目里面使用jsmind.js插件来制作思维导图页面完成需求
  11. 企业怎样优化用户体验?F5给出三条专业建议
  12. Pegasus education technical support
  13. 小学信息技术 Linux,小学信息技术教育教学计划
  14. ikbc c87 Win键失灵/锁定
  15. Google(谷歌)拼音输入法发布
  16. 项目实施分哪些阶段?
  17. Android rc 文件的使用
  18. 实现一个Android电子书阅读APP
  19. 如何用Java制作hwid验证_java - 将帐户登录+ HWID锁定添加到Java程序的最安全方法是什么? - SO中文参考 - www.soinside.com...
  20. 百度图片搜素接口,自动完成图片搜索和下载

热门文章

  1. Android手机游戏摇杆
  2. 21年阿里云 云栖大会云安全相关内容分享
  3. 看小镇做题人的悲歌 百感交集
  4. 面试官:连这些问题都不知道?就想要50k?
  5. HDLBits-Modules 题解【Verilog模块例化】(中文翻译+英文原文,可顺带学习英文)
  6. DBeaver Enterprise21.0 企业版激活方法 DBeaver mac激活 DBeaver
  7. cad批量打印_还为批量打印CAD图纸而发愁?只需五步,3秒打印百张图纸!
  8. 栋感光波-冲刺日志(第4次)
  9. 2021年高压电工证考试题库,高压电工试题解析
  10. 史上最强C语言教程----程序的编译与预处理(1)