SMU Summer 2023 Contest Round 14

A. Potion-making

就是解一个\(\frac{i}{i + j} = \frac{k}{100}\)方程,然后循环暴力找出答案

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

void solve(){
int k;
cin >> k; for(int i = 1;i <= 100;i ++){
for(int j = 0;j < 100;j ++){
if(i * 100 == k * (i + j)){
cout << i + j << '\n';
return ;
}
}
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while(T--){
solve();
} return 0;
}

B. Permutation Sort

其实就是特判首尾的情况

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

void solve(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i; vector<int> b(n);
iota(b.begin(), b.end(),1); if(a == b){
cout << 0 << '\n';
return ;
}else {
if(a[0] == 1 || a.back() == n)
cout << 1 << '\n';
else if(a[0] == n && a.back() == 1)
cout << 3 << '\n';
else cout << 2 << '\n';
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while(T--){
solve();
} return 0;
}

D. Armchairs

\(dp[i][j]\)表示前\(j\)个椅子放\(i\)个人的最短时间

当前座位为空时,可以放人也可以不放人.

否则,为前一个座位放\(i\)个人的最短时间

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n;
cin >> n;
vector<int> a(n + 1),b(1);
for(int i = 1;i <= n;i ++){
cin >> a[i];
if(a[i] == 1)
b.push_back(i);
} vector dp(n + 1, vector<int> (n + 1, 0x3f3f3f3f)); for(int i = 0;i <= n;i ++) dp[0][i] = 0; for(int i = 1;i < b.size();i ++){
for(int j = 1;j <= n;j ++){
if(a[j] == 0){
dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + abs(b[i] - j));
}else
dp[i][j] = dp[i][j - 1];
}
} cout << dp[b.size() - 1][n] << '\n';
return 0;
}

SMU Summer 2023 Contest Round 14的更多相关文章

  1. Codeforces Beta Round #14 (Div. 2)

    Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...

  2. BestCoder Round #14

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. hdu 5066 Harry And Physical Teacher(Bestcoder Round #14)

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  4. Codeforces Beta Round #14 (Div. 2) D. Two Paths 树形dp

    D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother ...

  5. Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题

    C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later A ...

  6. Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题

    B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...

  7. Codeforces Beta Round #14 (Div. 2) A. Letter 水题

    A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...

  8. Codeforces Beta Round #14 (Div. 2) D. Two Paths 树的直径

    题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory lim ...

  9. Codeforces Round #14 D. Two Paths(求树上两条不相交的路径的乘积最大值)

    题目链接:  http://codeforces.com/problemset/problem/14/D 思路:直接枚举每一天路径的两端,然后求以每一端为树根的树上最长路径,然后相乘就可以了. # ...

  10. 2014 Benelux Algorithm Programming Contest (BAPC 14)E

    题目链接:https://vjudge.net/contest/187496#problem/E E Excellent Engineers You are working for an agency ...

随机推荐

  1. vue cli4.0项目引入typescript

    现有的项目是采用vue cli4.0脚手架生成的,现在想要引入typescript. 1.执行安装命令 npm install --save-dev typescript npm install -- ...

  2. yum update和yum upgrade的区别

    看见网上很多关于这个问题的解答,但是大部分都是错的,误人子弟! 很多都是执行这两个命令,然后查看系统的变化.看似严谨,实则愚蠢至极. 就算不懂内核,也应该懂得什么是内核呀!也应该懂得内核是怎么进入的啊 ...

  3. 在 VSCode 中编写 Markdown 的进阶指南

    最新版的 Visual Studio Code 对 Markdown 的支持已显著提升,其在预览方面的体验甚至可以与 Markdown Preview Enhanced 插件相比.本文将介绍一些优化方 ...

  4. [UG 二次开发 python ] 截图,并用 opencv 显示出来

    需要 numpy,cv2 截图,去除背景,只显示主要部分 # nx: threaded from typing import Dict import NXOpen import numpy as np ...

  5. 写给rust初学者的教程(二):所有权、生存期

    这系列RUST教程一共三篇.这是第二篇,介绍RUST语言的关键概念,主要是所有权和生存期等. 第一篇:写给rust初学者的教程(一):枚举.特征.实现.模式匹配 在写第一篇中的练习代码时,不知道你有没 ...

  6. Spring AOP面向切面编程核心概念

    横切关注点 对那些方法进行拦截,拦截后怎么处理,这些就叫横切关注点 比如:权限认证.日志.事务 通知 Advice 在特定的切入点上执行的增强处理,有5种通知 用途:记录日志.控制事务.提前编写好通用 ...

  7. C#委托的2种调用方式

    第一种:直接调用,通过invoke方法: 第二种:这是第二种将委托作为方法的参数的间接调用: 下面举个栗子演示: using System; using System.Collections.Gene ...

  8. SQL_left join 和from 两个表的区别

    一个是普通的联接,结果中的记录在两个表中都有.一个是左外联接,结果中的记录在A表中存在,B表中不一定有.相当于a表为主体表,b为辅助表. 例子: mysql> select * from a;+ ...

  9. Divide Interval 题解

    背景 太逊了,调了三次才调出来,所以写篇题解寄念.LC好睿智 题意 给你两个数 \(a,b\),现在要从 \(a\) 跑到 \(b\),每次可以将当前的 \(a\) 拆分成 \(2^n\times m ...

  10. CF369D Valera and Fools 题解

    题目链接 Luogu Codeforces 题意简述 有 \(n\) 个人站成一排,每人手中有 \(k\) 发子弹,每次每人会向除自己外编号最小的人开枪,第 \(i\) 个人开枪的命中率为 \(p_i ...