• 2024“钉耙编程”中国大学生算法设计超级联赛(7)


    Problem - 7513 (hdu.edu.cn) 关于 agKc 实在不喜欢自动化于是啥都自己合成这件事

    思路:叶子的标记只会发生在叶子,并且标记应该返到根的下一层才是最优的,如果其他分路又有标,那么直接否定 标的数量满足的话,小于等于1. 再考虑总和 或 删一个最大的代价(这个代价必然是根节点的下一层之中的点)。

    先处理出根节点下一层的全部材料,并且把超过了1e9的标记。如果标记的个数cnt>=2,那么直接Impossible,否则如果cnt==1,再判是否ans>1e9. 否则如果cnt==0,ans-mx,再判ans>1e9?

    思路是这么个思路,主要是实现要实现好。

    1. const int maxx=1e9;
    2. int n,k;
    3. vector<int> vct[100005];
    4. unordered_map<int,bool> typ;
    5. int getProduct(int need,int x){
    6. if(need>maxx) return 0;
    7. if(!typ[x]){
    8. int zz;
    9. need*vct[x][0]>maxx?zz=0:zz=need*vct[x][0];
    10. return zz;
    11. }
    12. int res=0;
    13. for(int i=1;isize();i+=2){
    14. int cur=getProduct(need*vct[x][i-1],vct[x][i]); need*vct[x][i-1],累乘!
    15. if(cur==0) return 0;
    16. else res+=cur;
    17. if(res>maxx) return 0;
    18. }
    19. return res;
    20. }
    21. key:建一棵树
    22. 叶子的标记只会发生在叶子,并且标记应该返到根的下一层才是最优的,如果其他分路又有标,那么直接否定
    23. 标的数量满足的话,小于等于1. 再考虑总和 或 删一个最大的
    24. 关于 agKc 实在不喜欢自动化于是啥都自己合成这件事
    25. https://acm.hdu.edu.cn/contest/problem?cid=1130&pid=1009
    26. https://acm.hdu.edu.cn/showproblem.php?pid=7513
    27. void solve(){ 顶级模拟题..wa了22发才ac.
    28. cin>>n>>k;
    29. typ.clear();
    30. for(int i=1;i<=n;i++){
    31. vct[i].clear();
    32. int typ0; cin>>typ0;
    33. typ[i]=typ0;
    34. if(typ0){
    35. int zz; cin>>zz;
    36. for(int j=1;j<=2*zz;j++){
    37. int x; cin>>x;
    38. vct[i].emplace_back(x);
    39. }
    40. }
    41. else{
    42. int x; cin>>x;
    43. vct[i].emplace_back(x);
    44. }
    45. }
    46. vector<int> product;
    47. for(int i=1;isize();i+=2) product.emplace_back(getProduct(vct[k][i-1],vct[k][i]));
    48. int cnt=0,mx=0,sum=0;
    49. for(auto p:product){
    50. if(p==0) cnt++;
    51. mx=max(mx,p),sum+=p;
    52. }
    53. 最后这里要讨论好!!
    54. if(cnt>=2||cnt==1&&sum>maxx) cout<<"Impossible"<
    55. else if(cnt==0){
    56. sum-=mx; cnt==0才能减
    57. if(sum>maxx) cout<<"Impossible"<
    58. else cout<
    59. }
    60. else if(cnt==1) cout<
    61. }

  • 相关阅读:
    设计模式学习笔记 - 面向对象 - 1.面向对象到底讨论的是什么
    新手如何去做性能测试?
    【IDEA】idea恢复pom.xml文件显示灰色并带有删除线
    既然有HTTP协议,为什么还要有RPC
    网络支付安全:面临的风险与防范策略
    .net 使用IL生成代理类实现AOP对比Java Spring Boot的AOP
    【git 介绍】AhuntSun
    python珍藏宝藏学习资料
    mits6.081-lab2
    用智能文字识别技术赋能古彝文数字化之路
  • 原文地址:https://blog.csdn.net/qq_42643660/article/details/141093443