主要是因为马上要去参加女生赛,最近训练的补题。
Dashboard - 2023年中国大学生程序设计竞赛女生专场 - Codeforces
自己那天晚上是写完了最简单的两道,确实是能力不足,第三题是最长序列那题,也不是很难,但是自己看了下题解写出来的还是错了,还是看了别人的代码才写出来。
F 最长上升子序列
思路:还没有学习拓扑排序,但其实看了一点也不知道和拓扑有什么关系,太菜了,准备今天晚上再学下拓扑,图论是真的不会,然后主要思路是一直递增,碰到a[i]相同时说明最新的值和不递增,可以是递减的,所以排序后再换顺序,我一开始是这么想的,然后写了个sort,然后寄了(ㄒoㄒ)。
#include<iostream>
#include<vector>
using namespace std;
#define int long long
const int N = 1e6 + 7;
inline int read(){
int f = 1, x = 0;
char c = getchar();
while(c<'0'||c>'9'){
if(c=='-')
f = -1;
c = getchar();
}
while(c>='0'&&c<='9'){
x = x * 10 + c - '0';
c = getchar();
}
return f * x;
}
void write(int x){
if(x<0){
putchar('-'), x = -x;
}
if(x>9){
write(x / 10);
}
putchar(x % 10 + '0');
return;
}
bool cmp(int a,int b){
return a > b;
}
int n,f,maxx;
int a[N],p[N];
vector<int> v[N];
void solve(){
for (int i = 1; i <= n;++i){
a[i] = read();
if(a[i]>maxx){
if(a[i]-maxx>1)
f = 1;
maxx = a[i];
}
v[a[i]].push_back(i);
}
if(f==1){
printf("-1\n");
return;
}
int pp = 1;
for (int i = 1; i <= maxx;++i){
for (int j = v[i].size() - 1; j >= 0;--j){
int t = v[i][j];
p[t] = pp++;
}
}
for (int i = 1; i <= n;++i){
write(p[i]);
putchar(' ');
}
}
signed main(){
n = read();
int T = 1;
while(T--){
solve();
}
return 0;
}
L-养成游戏
思路:看到这题第一反应是看下复杂度,发现最高6的八次方,不会爆,所以直接用暴力,dfs,然后因为cf没有图片,但是本能开longlong
#include<iostream>
using namespace std;
#define int long long
int n, m, K;
const int N = 1e6 + 5;
int ans;
int A[N], op[N], ii[N], jj[N], a[N], b[N], d[N], v[N];
int cal(){//计算
int aa=0;
for (int i = 1; i <= m;++i){
if(op[i]==1&&a[i]*A[ii[i]]+b[i]*A[jj[i]]>=d[i])
aa += v[i];
if(op[i]==0&&a[i]*A[ii[i]]+b[i]*A[jj[i]]<=d[i])
aa += v[i];
}
return aa;
}
void dfs(int x,int y){
A[x] = y;
if(x==n){
ans = max(ans, cal());
return;
}
for (int i = 0; i <= K;++i){
dfs(x + 1, i);
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> K;
for (int i = 1; i <= m;++i){
cin >> ii[i] >> jj[i] >> op[i] >> a[i] >> b[i] >> d[i] >> v[i];
}
for (int i = 0; i <= K;++i){
dfs(1, i);
}
cout << ans << endl;
return 0;
}
G-精灵宝可梦对战
思路:一个结构体,然后也没有什么过多的判断,按照题目给的逻辑写,然后用一下队列,让循环比对更加快速,题解也说如果用正常的循环会t,还有个问题是不知道为什么每次都不能用位运算算奇偶,用了就wa了,但是正常取余不会,待会去找下原因。
tips:找到了,是因为我没有打括号,优先级出错了
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k;
struct pe{
int h, a, b, c, d, e, w,E;
};
queue<pe> A, B;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout. tie(0);
cin >> n >> m>>k;
int h, a, b, c, d, e, w;
for (int i = 1; i <= n;++i){
cin >> h >> a >> b >> c >> d >> e >> w;
pe x;
x.h = h, x.a = a, x.b = b, x.c = c, x.d = d, x.E = e, x.w = w;
x.e = 0;
A.push(x);
}for (int i = 1; i <= m;++i){
cin >> h >> a >> b >> c >> d >> e >> w;
pe x;
x.h = h, x.a = a, x.b = b, x.c = c, x.d = d, x.E = e, x.w = w;
x.e = 0;
B.push(x);
}
pe aa = A.front(), bb = B.front();
int cnt = 0;
k *= 2;
while(!A.empty()&&!B.empty()&&k>0){
int hit,p,q;
p = aa.a - bb.c > 0 ? aa.a - bb.c : 0;
q = aa.b - bb.d > 0 ? aa.b - bb.d : 0;
hit = max(q,p);
if(hit<aa.w&&aa.e>=aa.E){
hit = aa.w;
aa.e -= aa.E;
}
if(hit==q||hit==p)
aa.e++;
bb.h -= hit;
A.push(aa);
A.pop();
aa = A.front();
if(bb.h<=0){
B.pop();
bb = B.front();
}
swap(aa, bb);
swap(A, B);
k--;
cnt++;
}
if(k>=0&&!A.empty()&&!B.empty()){
cout << "Draw" << endl;
}
else if(cnt%2==0){
cout << "Bob" << endl;
}
else if(cnt%2==1){
cout << "Alice" << endl;
}
return 0;
}