传送门
A 函数
注意开long long
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define endl '\n'
const int N = 100010;
const int M = 110;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n;
cin>>n;
if(n&1)cout<<0<<endl;
else cout<<(ll)pow(2,n/2)<<endl;
}
int32_t main() {
IOS;
int h_h;
//cin >> h_h;
h_h = 1;
while (h_h--)solve();
return 0;
}
B 病毒
感觉就是一个简单的BFS,先把感染的格子都推入队列,如何跑一边BFS即可,用一个二维数组记录每个格子被感染的先后,最后再遍历一遍输出最后被感染的格子。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define endl '\n'
const int N = 100010;
const int M = 2010;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
int dis[M][M];
int g[M][M];
int dx[] {1, 0, -1, 0};
int dy[] {0, 1, 0, -1};
void solve() {
int n, m;
cin >> n >> m;
int k;
cin >> k;
vector<pair<int, int>> node;
while (k--) {
int x, y;
cin >> x >> y;
node.push_back({x, y});
g[x][y] = 1;
}
queue<pair<int, int>> q;
for (auto i: node) {
q.push({i.fi, i.se});
dis[i.fi][i.se] = 1;
}
while (q.size()) {
auto t = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int x = t.fi + dx[i];
int y = t.se + dy[i];
if (x >= 1 && x <= n && y >= 1 && y <= m && !g[x][y]) {
dis[x][y] = dis[t.fi][t.se] + 1;
g[x][y] = 1;
q.push({x,y});
}
}
}
int a, b;
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
//cout << dis[i][j] << ' ';
if (dis[i][j] > ans) {
a = i;
b = j;
ans = dis[i][j];
}
}
//cout << endl;
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= m; j++) {
// cout << g[i][j] << ' ';
// }
// cout << endl;
// }
cout << a << ' ' << b << endl;
}
int32_t main() {
IOS;
int h_h;
//cin >> h_h;
h_h = 1;
while (h_h--)solve();
return 0;
}
C 鸡尾酒
贪心,我们先把每种酒按照1:1的比例算出来,以最小的那种酒作为标准,去取其他的酒,最后的结果再和V取一个min即可。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define endl '\n'
const int N = 100010;
const int M = 2010;
const int MOD = 1e9 + 7;
const int EPS = 1e-8;
using namespace std;
void solve() {
int n, v;
cin >> n >> v;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < n; i++)cin >> b[i];
double mn = 100010;
for (int i = 0; i < n; i++) {
mn = min(mn, b[i] * 1.0 / a[i]);
}
//cout<<mn<<endl;
double ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] * mn - b[i] > EPS)ans += b[i];
else ans += a[i] * mn;
}
if (ans - v >= EPS)ans = v;
printf("%.10f\n", ans);
}
int32_t main() {
IOS;
int h_h;
//cin >> h_h;
h_h = 1;
while (h_h--)solve();
return 0;
}