当前位置:网站首页>Xiaosha's lunch
Xiaosha's lunch
2022-06-30 05:21:00 【whitewall_ nine】
// Problem: Xiaosha's lunch
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/problem/231178
// Memory Limit: 2 MB
// Time Limit: 231178000 ms
// 2022-02-15 23:23:06
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
const int N = 1e3 + 10;
void solve() {
int n;
int a[N];
ll f[N] = {0};
ll suf[N] = {0};
int cnt = 0;
cin >> n;
ll x = 0, y ;
for (int i = 1; i<= n ;i++){
int t;
cin >> t;
if (t == 1) x ++;
else {
++cnt;
a[cnt] = t;
}
}
sort(a +1, a + 1 + cnt);
for (int i = cnt; i >= 1;i --) {
suf[i] = suf[i + 1] + a[i];
f[i] = suf[i] - f[i + 1];
if (a[i] >= 4) f[i] = max (f[i], f[i + 1] + a[i] - 4);
}
x = suf[1] - f[1] + x, y = f[1];
if (x > y) puts("xiaohonwin");
else if (x == y) puts("loss");
else puts("xiaoshawin");
}
int main () {
int t;
cin >> t;
while (t --) solve();
return 0;
}
First, we need to understand a key property , By looking at a ring , We can find that for less than 4 We can't get it , For greater than or equal to 4 Can get a[i] -4 At most Then, for multiple rings, we need to consider the following for the current number of rings , So we go from big to small dp, In this way, you can be greedy for the current when you know the later . And then take max That's it
边栏推荐
- East Tower attack and defense world - XSS bypasses the safety dog
- Rotation, translation and scaling of unity VR objects
- Question mark (?) in Cron expression Use of
- Chapter 11 advanced data management of OpenGL super classic (version 7)
- OpenGL draws model on QT platform to solve the problem of initializing VAO and VBO
- VFPBS上传EXCEL并保存MSSQL到数据库中
- The minecraft server address cannot be refreshed.
- Unity- the camera follows the player
- [vcs+verdi joint simulation] ~ take the counter as an example
- 旋转框目标检测mmrotate v0.3.1 学习配置
猜你喜欢

14x1.5cm vertical label is a little difficult, VFP calls bartender to print

Baiwen.com 7 days Internet of things smart home learning experience punch in the third day

Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation

14x1.5cm竖向标签有点难,VFP调用BarTender来打印

ParticleSystem in the official Manual of unity_ Collision module

Ugui uses its own function to realize reverse mask

Unity + hololens2 performance test

Generate a slice of mesh Foundation

Virtual and pure virtual destructions

Connect() and disconnect() of socket in C #
随机推荐
Unity project hosting platform plasticscm (learn to use 2)
旋转框目标检测mmrotate v0.3.1入门
VFPBS上传EXCEL并保存MSSQL到数据库中
Force buckle 977 Square of ordered array
Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
2021-07-29 compilation of Cura in ubantu18.04
Pyinstaller flash back
GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
Unity publishing /build settings
Unity + hololens2 performance test
Operation file file class method
Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation
Another download address for typro
GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
After reading who moved my cheese
The fourth day of learning C language for Asian people
How can the international trading platform for frying US crude oil guarantee capital security?
Access is denied encountered when vfpbs calls excel under IIS
Nestjs introduction and environment construction
[typescript] experimentaldecorators of vscode stepping pit