zoukankan      html  css  js  c++  java
  • CF 767#

    A题的话,用一个priority_queue维护一下,直到最大的符合要求才出来,,(一开始记错了,,2333写成了小根堆。。。)

     1 #include<bits/stdc++.h>
     2 #define N 150005
     3 #define LL long long
     4 #define inf 0x3f3f3f3f
     5 #define lowbit(x) x&(-x)   
     6 using namespace std;
     7 inline int ra()
     8 {
     9     int x=0,f=1; char ch=getchar();
    10     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    11     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    12     return x*f;
    13 }
    14 priority_queue<int  >q;
    15 int main()
    16 {
    17     int n=ra(),t=n;
    18     for (int i=1; i<=n; i++)
    19     {
    20         int x=ra();
    21         q.push(x);
    22         while (!q.empty())
    23         {
    24             int y=q.top();
    25             if (y==t)
    26             {
    27                 printf("%d ",y);
    28                 q.pop();
    29                 t--;
    30             }
    31             else break;
    32         }
    33         cout<<endl;
    34     }
    35     return 0;
    36 }

    B题,弃疗,不会,s(神)b(犇)题,码力不够,虚,弃疗。

    C题就是普普通通搜一下就好了,然后还是写不对,太虚了。。。一开始的程序真是bug++啊,,,,(一开始只判了2个点合法就行,然后是有特殊情况的,比如就只能分成2块,尴尬了。。。。所以又记录一个点)

     1 #include<bits/stdc++.h>
     2 #define N 1000005
     3 #define LL long long
     4 #define inf 0x3f3f3f3f
     5 #define lowbit(x) x&(-x)   
     6 using namespace std;
     7 inline int ra()
     8 {
     9     int x=0,f=1; char ch=getchar();
    10     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    11     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    12     return x*f;
    13 }
    14 struct node{
    15     int to,next;
    16 }e[N];
    17 int w[N],n,ans1,ans2;
    18 bool flag;
    19 int head[N],cnt,tot,root,ans3;
    20 void insert(int x, int y)
    21 {
    22     e[++cnt].to=y; e[cnt].next=head[x]; head[x]=cnt;
    23 }
    24 void dfs(int x)
    25 {
    26     if (flag) return;
    27     for (int i=head[x];i;i=e[i].next)
    28     {
    29         dfs(e[i].to);
    30         w[x]+=w[e[i].to];
    31     }
    32     if (w[x]==tot/3 && !ans1) ans1=x,w[x]=0;
    33     else if (w[x]==tot/3 && ans1 && !ans2) ans2=x,w[x]=0; 
    34     else if (w[x]==tot/3 && ans1 && ans2 && !ans3) ans3=x;
    35 }
    36 int main()
    37 {
    38     n=ra();
    39     for (int i=1; i<=n; i++)
    40     {
    41         int x=ra();
    42         if (x!=0) insert(x,i); else root=i; w[i]=ra();
    43         tot+=w[i];
    44     }
    45     if (tot%3)
    46     {
    47         cout<<"-1";
    48         return 0;
    49     }
    50     dfs(root);
    51     if (ans1 && ans2 && ans3)
    52     {
    53         cout<<ans1<<" "<<ans2;
    54         return 0;
    55     }
    56     cout<<"-1";
    57     return 0;
    58 }
  • 相关阅读:
    南京周边城市两日游方案
    电梯演说
    需求分析
    敏捷开发
    课堂练习 选择团队类型
    结对项目小DEMO
    分析图书管理系统的5W1H
    项目风险分析作业
    旅游方案选择
    图书管理系统需求规格
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6435537.html
Copyright © 2011-2022 走看看