当前位置:网站首页>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
边栏推荐
- Unity limited time use limited trial time and use times
- Pytorch的安装以及入门使用
- Pit of smoothstep node in shadergraph
- ParticleSystem in the official Manual of unity_ Collision module
- Unity3d packaging and publishing APK process
- Responding with flow layout
- Unity3d get screen width and height
- Unity2019.3.8f1 development environment configuration of hololens2
- Question mark (?) in Cron expression Use of
- Connect() and disconnect() of socket in C #
猜你喜欢

Database base (Study & review for self use)

Unity + hololens2 performance test

Force buckle 27 Removing Elements
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Unity3d packaging and publishing APK process

Pytorch的安装以及入门使用
![[learning notes] AssetBundle, xlua, hot update (use steps)](/img/59/9d9f31cfe55a908f2f0705e95ecc05.jpg)
[learning notes] AssetBundle, xlua, hot update (use steps)

The fourth day of learning C language for Asian people

Unity scroll view element drag and drop to automatically adsorb centering and card effect

Introduction to mmcv common APIs
随机推荐
Unity application class and data file path
终端便捷ssh(免密)连接
Revit二次開發---未打開項目使用面板功能
9. naive Bayes
Responding with flow layout
Initial environment configuration of the list of OpenGL super classic (version 7) vs2019
Assembly learning tutorial: accessing memory (3)
How to judge the quality of network transformer? What symptom is network filter transformer broken?
Unity profiler performance analysis
Does the tester need to analyze the cause of the bug?
图扑软件基于钻孔数据的三维地质模型可视化
Display steerable 3D model in front of unity UI
Unity ugui text value suspended enlarged display add text background
Unity scroll view element drag and drop to automatically adsorb centering and card effect
[typescript] experimentaldecorators of vscode stepping pit
Unity 3D model operation and UI conflict Scrollview
East Tower attack and defense world - XSS bypasses the safety dog
Rotation, translation and scaling of unity VR objects
Unity project hosting platform plasticscm (learn to use 1)
Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation