当前位置:网站首页>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
边栏推荐
- Access is denied encountered when vfpbs calls excel under IIS
- Expansion method of unity scanning circle
- Nestjs introduction and environment construction
- Untiy3d controls scene screenshots through external JSON files
- Question mark (?) in Cron expression Use of
- Force buckle 977 Square of ordered array
- Nestjs配置静态资源,模板引擎以及Post示例
- unity 扫描圈 圆扩展方法
- Assembly learning tutorial: accessing memory (3)
- 图扑软件基于钻孔数据的三维地质模型可视化
猜你喜欢

The fourth day of learning C language for Asian people

How to judge the quality of network transformer? What symptom is network filter transformer broken?

Ugui uses its own function to realize reverse mask

Super comprehensive summary | related improvement codes of orb-slam2 / orb-slam3!

Pit of smoothstep node in shadergraph

Unity3d packaging and publishing APK process

网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?

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

Generate a slice of mesh Foundation
![[note] usage model tree of the unity resource tree structure virtualizingtreeview](/img/3e/fe5610c797a14554ad735172c3ab54.jpg)
[note] usage model tree of the unity resource tree structure virtualizingtreeview
随机推荐
9. naive Bayes
2021-07-29 compilation of Cura in ubantu18.04
Unity mobile end sliding screen rotation
Visualization of 3D geological model based on borehole data by map flapping software
《谁动了我的奶酪》读后感
Tensorflow2 of ubantu18.04 X installation
Unity3d position the model, rotate, drag and zoom around the model to obtain the center point of the model
Operation file file class method
UnityEngine. JsonUtility. The pit of fromjason()
Unity3d get screen width and height
【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
Database base (Study & review for self use)
Chapter 12 pipeline monitoring of OpenGL super classic (version 7)
Unityshader learning notes - Basic Attributes
Virtual and pure virtual destructions
Unity scroll view element drag and drop to automatically adsorb centering and card effect
Unity dotween plug-in description
How to prevent source code leakage in enterprises and institutions
The file has been downloaded incorrectly!