P9117 [春季测试 2023] 涂色游戏【民间数据】
#include <bits/stdc++.h>
using namespace std;
// 一个TLE
int T, n, m, q, opt, x, c;
int main()
{
cin >> T;
for(int i = 0; i < T; i++){
cin >> n >> m >> q;
int mp[n + 1][m + 1];
memset(mp, 0, sizeof(mp));
for(int j = 1; j <= q; j++){
cin >> opt >> x >> c;
if(opt == 0){//行
for(int i = 1; i <= m; i++)
mp[x][i] = c;
}else if(opt == 1){//列
for(int i = 1; i <= n; i++)
mp[i][x] = c;
}
}
//输出结果
for(int a = 1; a <= n; a++){
for(int b = 1; b <= m; b++)
cout << mp[a][b] << " ";
cout << endl;
}
}
return 0;
}
P9118 [春季测试 2023] 幂次【民间数据】
#include <bits/stdc++.h>
using namespace std;
//70分
typedef long long ll;
// 快速幂
ll mypow(ll a, ll b){
ll ans = 1;
while(b){
if(b % 2 == 1) ans *= a;
b /= 2;
a *= a;
}
return ans;
}
int main()
{
ll n, k;
set<ll> sum;
cin >> n >> k;
if(k == 1) cout << n;
else{
for(ll i = 2; i < n; i++){
if(mypow(i, k) > n) break;
for(ll j = k; ; j++){
ll t = mypow(i, j);
if(t > n) break;
else sum.insert(t);
}
}
cout << sum.size() + 1;
}
return 0;
}
P9119 [春季测试 2023] 圣诞树【民间数据】
正解应该是状态压缩dp,但不会写
//贪心
#include <bits/stdc++.h>
using namespace std;
//贪心 75分
#define ld long double
ld inf = 191999999;
struct edge{
int v;
ld len;
}dis[1005][1005];
bool vis[1005];
int n, sum;
ld x[1005], y[1005], maxn = -inf, k = -1e7;
ld d(int i, int j){//开不开根都一样
return ((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
bool cmp(const edge &x, const edge &y){
return x.len < y.len;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
if(y[i] > maxn) maxn = y[i], k = i;//找到起点
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
dis[i][j].v = j;//除自己外所有点
if(i == j) dis[i][j].len = inf;//无路
else dis[i][j].len = d(i, j);
}
sum = 1;
int st = k;//y最大的为起点
cout << st << " ";
vis[st] = 1;
while(sum != n){
sort(dis[st] + 1, dis[st] + n + 1, cmp);//按照距离从小到大排序
int op = 1;
while(vis[dis[st][op].v]) op++;//访问过继续找下一个小的路径
st = dis[st][op].v;
vis[st] = 1;
cout << st << " ";
sum++;
}
return 0;
}
P9120 [春季测试 2023] 密码锁【民间数据】
完全不会写