• 「国庆训练」ArcSoft's Office Rearrangement(HDU-5933)


    题目与分析

    题解见https://blog.csdn.net/cmershen/article/details/53200922。
    训练赛场上我们写出来了——在4小时50分钟的时候。。。激情补题啊。。。问题是这就是个尬模,我赛场上的写法和这个差不多。。。然后疯狂wa。。。
    最后AC的是换了个写法。。。。然后现在我再重头写我都一股子蛋疼,特么找不到问题在哪里是真的骚,以后多训练才是王道。(之后回顾的时候再找找看问题吧)

    代码

    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <stack>
    #define MP make_pair
    #define PB push_back
    #define fi first
    #define se second
    #define ZERO(x) memset((x), 0, sizeof(x))
    #define ALL(x) (x).begin(),(x).end()
    #define rep(i, a, b) for (int i = (a); i <= (b); ++i)
    #define per(i, a, b) for (int i = (a); i >= (b); --i)
    #define QUICKIO                  
        ios::sync_with_stdio(false); 
        cin.tie(0);                  
        cout.tie(0);
    #define MS(x,y) memset(x,y,sizeof(x))
    using namespace std;
    typedef long long ll;
    stack<ll> stk;
    ll arr[100005];
    int main()
    {
    	int T; scanf("%d
    ", &T);
    	rep(kase,1,T)
    	{
    		while(!stk.empty()) stk.pop();
    		int n,k; scanf("%d%d", &n, &k);
    		ll sum=0;
    		rep(i,1,n)
    		{
    			scanf("%lld", &arr[i]);
    			sum+=arr[i];
    		}
    		ll ans=-1;
    		if(sum%k==0)
    		{
    			per(i,n,1)
    			{
    				stk.push(arr[i]);
    			}
    		    ans=0;
    			ll ave=sum/k, now=0;
    			while(!stk.empty())
    			{
    				now+=stk.top(); stk.pop();
    				if(now==ave) now=0;
    				else if(now<ave)
    				{
    					while(now<ave)
    					{
    						now+=stk.top(); stk.pop();
    						ans++;
    					}
    					if(now==ave) now=0;
    					else
    					{
    						if(now%ave) // 这边是最神奇的地方:我不知道为什么,但是如果这边和下面整合起来写会TLE!!!这真是太神奇了,也许是其他地方的bug?
    						{
    							ans+=now/ave;
    							stk.push(now%ave);
    						}
    						else ans+=now/ave-1;
    						now=0;
    					}
    				}
    				else
    				{
    					if(now%ave)
    					{
    						ans+=now/ave;
    						stk.push(now%ave);
    					}
    					else ans+=now/ave-1;
    					now=0;
    				}
    			}		
    		}
    		printf("Case #%d: %lld
    ", kase, ans);
    	}
    		 
    	return 0;
    }
    
    
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    SVN Windows环境搭建,简洁演示
    SVN-linux配置
    链接文本在a标签内标签里也可以用driver.find_element_by_link_text
    selenium python自动化简明演示
    关键字中mysql数据库查询条件带中文无结果解决办法
    python 最短路径
    python 难度分割
    c语言实现一个高铁乘客管理系统
    Linux(Ubuntu)系统安装图文教程
    字符串排序
  • 原文地址:https://www.cnblogs.com/samhx/p/HDU-5933.html
Copyright © 2020-2023  润新知