标签:AtCoder f2 Beginner Contest int f1 ++ ans mod
LINE Verda Programming Contest(AtCoder Beginner Contest 263)
https://atcoder.jp/contests/abc263
F G 待补
A - Full House
输入5个数,判断是否满足两个数相等,另外三个数相等
#include <bits/stdc++.h>
using namespace std;
int main () {
set<int> s;
map<int, int> mp;
int n = 5, x;
while (n --) {
cin >> x;
s.insert(x);
mp[x] ++;
}
if (mp.size() != 2) {
cout << "No";
return 0;
}
bool f1 = false, f2 = false;
for (auto i : mp) {
if (i.second == 2) f1 = true;
if (i.second == 3) f2 = true;
}
if (f1 && f2) {
cout << "Yes";
}
else cout << "No";
}
B - Ancestor
找爸爸:i的爸爸是pi,问n和1之间隔了几代
挨个找过去即可
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int a[N], n;
int main () {
cin >> n;
for (int i = 2; i <= n; i ++) cin >> a[i];
int ans = 0, x = n;
while (1) {
x = a[x];
ans ++;
if (x == 1) break;
}
cout << ans;
}
C - Monotonically Increasing
输出所有长度为n,可选数范围为1-m的严格上升序列
全排列 + 筛选
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a;
for (int i = 0; i < n; i++)
a.push_back(0);
for (int i = 0; i < m - n; i++)
a.push_back(1);
for (int i = 0; i < m; i++)
if (a[i] == 0)
cout << i + 1 << " ";
cout << endl;
while (next_permutation(a.begin(), a.end())) {
for (int i = 0; i < m; i++)
if (a[i] == 0)
cout << i + 1 << " ";
cout << endl;
}
}
//输出所有长度为2,数字范围在1~m的严格上升序列
D - Left Right Operation
题意
进行如下操作各一次:
- 把 \(a_1,a_2,...,a_x\) 全替换为 L;
- 把 \(a_{n-y+1},...,a_{n-1},a_n\) 全替换为 R;
\(0\leq x,y\leq n\)
问a的和最小为多少
分析
f1[i]表示1i最小可能和,f2[i]表示in最小可能和
则答案在f1[i]+f2[i+1]中取(尽可能替换更多的,故枚举分界点)
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 5, inf = 1e18;
int n, a[N], l, r;
int f1[N], f2[N];
signed main () {
cin >> n >> l >> r;
for (int i = 0; i < n; i ++) cin >> a[i];
f1[0] = min (a[0], l), f2[n-1] = min (a[n-1], r);
for (int i = 1; i < n; i ++)
f1[i] = min (f1[i-1] + a[i], l*(i+1));
for (int i = n-2; i >= 0; i --)
f2[i] = min (f2[i+1] + a[i], r*(n-i));
int ans = min (f2[0], f1[n-1]);
for (int i = 0; i < n-1; i ++) ans = min (ans, f1[i]+f2[i+1]);
cout << ans << endl;
}
//把前x全变成L,或把后y全变成R
//只能各操作一次
E - Sugoroku 3
题意
1n-1每个上都有一个骰子 标签:AtCoder,f2,Beginner,Contest,int,f1,++,ans,mod
来源: https://www.cnblogs.com/CTing/p/16558563.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。