freee Programming Contest 2023(AtCoder Beginner Contest 310) - AtCoder
A - Order Something Else (atcoder.jp)
题意是在买一道菜的情况下可以将原为\(P\)元的饮料优惠到\(Q\)元,否则就按原价买
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n,p,q;
cin >> n >> p >> q;
vector<int> a(n);
for(auto &i : a)
cin >> i;
int ans = p;
for(auto i : a){
if(q + i < ans)
ans = q + i;
}
cout << ans << endl;
return 0;
}
B - Strictly Superior (atcoder.jp)
题意是有\(N\)种产品,每种产品有最多有\(M\)\((1 < C_i < M)\)种功能,定义第\(i\)种产品的第\(C_i\)种功能为\(F_{i,C_i}\),现满足以下条件则说明存在有一种商品严格大于另一种商品:
-
\(P_i \geq P_j\)
-
第\(j\)种商品包含第\(i\)种商品的全部功能
-
$P_i > P_j $ 或者 第\(j\)种商品的功能比第\(i\)种更多
纯模拟,注意对条件的判断.
繁杂版(bushi
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> PII;
int n,m;
void solve() {
cin >> n >> m;
multimap<int,vector<int>> prj;
for(int i = 0;i < n;i ++){
int p,k;
cin >> p >> k;
vector<int> o;
for(int j = 0;j < k ;j ++){
int y;
cin >> y;
o.push_back(y);
}
prj.insert({p,o});
}
bool f = false;
for(auto i : prj){
for(auto j : prj){
if(i == j) continue;
if(j.first <= i.first && j.second.size() >= i.second.size()){
for(int k = 0;k < i.second.size() ;k++){
if(std::find(j.second.begin(), j.second.end(),i.second[k]) == j.second.end())
break;
if (k == i.second.size() - 1){
if(j.first < i.first || j.second.size() > i.second.size())
f = true;
}
}
}
}
}
cout << (f ? "Yes" : "No") << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
简洁版(\(jiangly\)的
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
std::vector<int> P(N);
std::vector<std::bitset<100>> F(N);
for (int i = 0; i < N; i++) {
std::cin >> P[i];
int C;
std::cin >> C;
while (C--) {
int x;
std::cin >> x;
F[i][x - 1] = 1;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (P[i] <= P[j] && (F[i] & F[j]) == F[j] && (P[i] < P[j] || F[i] != F[j])) {
std::cout << "Yes\n";
return 0;
}
}
}
std::cout << "No\n";
return 0;
}
C - Reversible (atcoder.jp)
题意就是相同或相反的字符串算一个球棒,输出一共有多少球棒
每次判断一下就行
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
using namespace std;
int n,m;
void solve() {
cin >> n;
set<string> a;
map<string,int> mps;
for(int i = 0;i < n;i ++){
string s,ss;
cin >> s;
ss = s;
std::reverse(s.begin(), s.end());
if(mps.count(s))
continue;
mps[ss]++;
a.insert(ss);
}
cout << a.size() << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
放份\(jiangly\)的学习下(
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<std::string> S(N);
for (int i = 0; i < N; i++) {
std::cin >> S[i];
auto T = std::string(S[i].rbegin(), S[i].rend());
if (T < S[i]) {
S[i] = T;
}
}
auto ans = (std::set(S.begin(), S.end()).size());
std::cout << ans << "\n";
return 0;
}
D - Peaceful Teams (atcoder.jp)
后面没做出来了,不过看了\(jiangly\)的也算有了思路(bushi
题意就是有\(M\)对有矛盾的队员不能放一个队里,问最多能组成多少不同的队
因为数据范围较小所以可以直接搜就完了
\(c(x)\)代表的是第\(x\)个人被分配到哪一队了,\(max(y,i+ 1)\)是带入当前已经有人被分配的最大队伍数
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
using namespace std;
void solve(){
int t;
cin >> n >> t >> m;
vector<int> a(m),b(m);
for(int i = 0;i < m;i ++){
cin >> a[i] >> b[i];
a[i] --,b[i] --;
}
vector<int> c(n);
int ans = 0;
auto dfs = [&](auto self, int x,int y){
if(x == n){
if(y != t){
return ;
}
bool ok = true;
for(int i = 0;i < m;i ++){
if(c[a[i]] == c[b[i]])
ok = false;
}
ans += ok;
return ;
}
for(int i = 0;i <= y;i ++){
c[x] = i;
self(self, x + 1, max(y,i + 1));
}
};
dfs(dfs,0,0);
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> ie_scholar;
while(Ke_scholar--)
solve();
return 0;
}
就不放\(jiangly\)的了,因为跟他一样(
标签:std,AtCoder,Beginner,Contest,int,cin,long,++,define From: https://www.cnblogs.com/Kescholar/p/17558122.html