题解 | #The Grand Tournament#

The Grand Tournament

https://ac.nowcoder.com/acm/contest/18713/A

两个数组 一个存原数组 一个存排序后的数组

用两个变量分别存数的和,相同时即可分为一组,即组内和相同 数相同

#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mem(a, b) memset(a, b, sizeof(a))
#define DEBUG(x) cerr << #x << '=' << x << endl
#define repl(i,x,y) for(int i=x;i<=y; ++i)
#define repr(i,k,n) for(int i=x;i>=y; --i)
template <typename T>
inline void read(T& f){f = 0;T fu = 1;char c = getchar();while (c < '0' || c > '9'){if (c == '-'){fu = -1;}c = getchar();}while (c >= '0' && c <= '9'){f = (f << 3) + (f << 1) + (c & 15);c = getchar();}f *= fu;}
template <typename T>
void print(T x){if (x < 0) putchar('-'), x = -x;if (x < 10) putchar(x + 48);else print(x / 10), putchar(x % 10 + 48);}
template <typename T>
void print(T x, char t){print(x);putchar(t);}
typedef long long ll;
const int M = 1e9+7;
const int N = 1e6+100;
const int mod = 998244353;
const int maxn = 100;
int n, m, t,l,k,r,c;
int a[N],b[N];
signed main()
{
    read(n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        read(a[i]);
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    ll sum1=0;
    ll sum2=0;
    for(int i=1;i<=n;i++)
    {
        sum1+=a[i];
        sum2+=b[i];
        if(sum1==sum2) ans++;
    }
    cout<<ans<<endl;
}
全部评论
???随便找个代码就说是20年沈阳A是把
点赞 回复 分享
发布于 2022-11-05 14:48 浙江

相关推荐

03-03 23:12
已编辑
北京邮电大学 Java
书海为家:我来给一点点小建议,因为毕竟还在学校不像工作几年的老鸟有丰富的项目经验,面试官在面试在校生的时候更关注咱们同学的做事逻辑和思路,所以最好在简历中描述下自己做过项目的完整过程,比如需求怎么来的,你对需求的解读,你想到的解决办法,遇到困难如何找人求助,最终项目做成了什么程度,你从中收获了哪些技能,你有什么感悟。
你的简历改到第几版了
点赞 评论 收藏
分享
评论
9
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务