zoukankan      html  css  js  c++  java
  • 题解 P1334 【瑞瑞的木板】

    声明:本题解已经与其他题解重合,

    且存在压行情况。


    首先,这个题解是我有了惨痛的教训:全部WA...
    先发一个CODE做声明:

    #include <bits/stdc++.h>
    //万能头文件,优先队列OI请用<queue>/<algorithm>
    #define lli long long int
    using namespace std;
    priority_queue<lli,vector<lli>,greater<lli> >cz;
    void work()
    {
    	lli n,x,y,ans=0,temp;
    	scanf("%lld",&n);
    	for (lli i=1;i<=n;i++)
    	{scanf("%lld",&temp);cz.push(temp);}
    	for (lli i=1;i<=n-1;i++)
    	{
    		x=cz.top();cz.pop();
    		y=cz.top();cz.pop();
    		ans+=(x+y);
    		cz.push(x+y);
    	}
    	printf("%lld",ans);
    } 
    int main()
    {
    	work();
    	return 0;
    }
    

    问题出在哪里呢?看我原先的代码:

    #include <bits/stdc++.h>
    #define lli long long int
    using namespace std;
    priority_queue<lli,vector<lli>,greater<lli> >cz;
    lli work(lli n)
    {
    	lli x,y,ans=0,temp;
    	/*完全相同*/
    	return ans;
    } 
    int main()
    {
    	lli n;scanf("%lld",n); 
    	printf("%lld",work(n));
    	return 0;
    }
    

    这样运行出来的数据会非常令人难受,
    因为long long int 类型的数据很难转移,
    我们传给work里面的数据有可能是一个错误的数字,
    甚至说程序直接卡崩(RE)...
    所以解决方案:不要在主函数里输入输出,直接在work运行即可...

  • 相关阅读:
    C#操作Windows控制面板
    WPF打印控件内容
    LINQ函数
    通过实现System.IComparable接口的CompareTo方法对两个类进行比较
    泛型和约束
    CSS样式基础总结
    C#调用百度高精度IP定位API通过IP获取地址
    软件下载路径
    RNN学习资料
    mysql 不能插入中文记录
  • 原文地址:https://www.cnblogs.com/jelly123/p/10385887.html
Copyright © 2011-2022 走看看