CF 546B Soldier and Badges

来源:互联网 发布:ftp阿里云服务器配置 编辑:程序博客网 时间:2024/06/05 11:51

其实还是挺水的

注意两个问题 

最终结果要定义longlong

bool 数组要开的大一些

#include <iostream>#include <cstdio>#include <cstring>using namespace std;bool pos[100000];long long  data[3100];int main(){    int n;    while(~scanf("%d",&n))    {        long long  ans = 0;        memset(pos,0,sizeof(pos));        for(int i = 1;i <= n;i ++)        {            scanf("%d",&data[i]);            if(pos[data[i]] == 0)                pos[data[i]] = 1;            else if(pos[data[i]])            {                for(int j = data[i] + 1 ;;j ++)                {                    if(pos[j] == 0)                    {                        ans += j-data[i];                        pos[j] = 1;                        break;                    }                }            }        }       cout<<ans<<endl;    }    return 0;}


0 0
原创粉丝点击