ZOJ - 3932 Handshakes 【水】

mac2022-06-30  29

题目链接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932

题意 给出 N 个人,然后 1-N 然后 从 1 - N 一个一个的进,每个人 进去 都可以在在座的人握手,然后给出那个人握手的次数 要求出 握手次数的最大值

思路 只要进来的人握手次数>=1 那么 本来已经在区域内的人 那个当前这个人的握手次数 就是其给出的握手次数,本来已经在区域内的人握手次数都+1,因为都是有可能的

然后实际发现 ,可以FOR 一遍 不断更新当前状态和已经在区域内的状态 就可以了

AC代码

#include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <ctype.h> #include <algorithm> #include <deque> #include <vector> #include <map> #include <stack> #include <set> #include <numeric> #include <sstream> #include <iomanip> #include <limits> #define CLR(a) memset(a, 0, sizeof(a)) #define pb push_back using namespace std; const int maxn = 1e5 + 5; int main() { int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); int id, ans = 0; for (int i = 0; i < n; i++) { scanf("%d", &id); if(id) ans = max(ans + 1, id); } printf("%d\n", ans); }

转载于:https://www.cnblogs.com/Dup4/p/9433161.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)