【组队赛#9】USACO 2006 January Bronze

【A题】A. Stump Removal 链接click here~~

【题目大意】一排高低不平的树桩,需要用炸弹全部炸掉,如果一个树桩的前面和后面的树桩高度都比它小,炸弹爆炸的时候会同时炸掉,求尽可能少的放置炸弹的数目,输出树桩的编号

【解题思路】 理解题意,从左往右扫,如果当前位置右边或左边的比它低了或相等,那么就把这个位置炸掉,然后把能炸的都炸掉,判断当前树桩前面的和后面的高度比较,

核心代码

 for(int i=1;i<=n+1;i++)
    {
        if(a[i]>=a[i-1]&&a[i]>=a[i+1])
        cout<<i<<endl;
    }

【F题】F. Dollar Dayz BNU 14323

【题目大意】大数!求解钱币组合问题,坑题一道~~

代码:

/*
Author:HRW
大数!
*/
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001;
struct bign
{
    int len,s[maxn];
    bign()
    {
        memset(s,0,sizeof(s));
        len = 1;
    }
    bign operator = (const char *num)
    {
        len = strlen(num);
        for(int i=0; i<len; i++)s[i] = num[len-i-1] - '0';
        return *this;
    }
    bign operator = (int num)
    {
        char s[maxn];
        sprintf(s,"%d",num);
        *this = s;
        return *this;
    }
    bign(int num)
    {
        *this = num;
    }
    bign(const char *num)
    {
        *this = num ;
    }
    string str()const
    {
        string res = "";
        for(int i=0; i<len; i++)
            res = (char)(s[i] + '0') + res;
        if (res == "")res = "0";
        return res;
    }
    bign operator + (const bign& b)const
    {
        bign c;
        c.len = 0;
        for(int i=0,g = 0; g|| i<max(len,b.len); i++)
        {
            int x = g;
            if(i<len) x+= s[i];
            if(i<b.len) x+=b.s[i];
            c.s[c.len++] = x%10;
            g = x/10;
        }
        return c;
    }
    void clean()
    {
        while(len > 1 && !s[len-1]) len--;
    }
    bign operator += (const bign& b)
    {
        *this = *this + b;
        return *this;
    }
};
istream& operator >>(istream &in, bign& x)
{
    string s;
    in>>s;
    x = s.c_str();
    return in;
}
ostream& operator << (ostream &out, const bign& x)
{
    out << x.str();
    return out;
}
bign AC[1002];
int main()
{
    int n,k;
    while(cin>>n>>k)
    {
        AC[0] = 1;
        for(int i=1; i<=k; i++)
            for(int j=i; j<=n; j++)
               AC[j]+=AC[j-i];
            cout<<AC[n]<<endl;
    }
    return 0;
}

【E题】E. Redundant Paths BNU14319

【题目大意】给你一个连通的无向图G,至少要添加几条边,才能使其变为双连通图,和POJ 3177一样

【解题思路】一个有桥的连通图要变为双连通图的话,把双连通图收缩为一个点,形成一颗树,需要加的边为(L+1)/2,L为叶子节点个数

ps:BNU竟然加外挂会超时~~orz,以后还是得多注意。。

代码:

/*
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=5010;//点数
const int maxm=20100;//边数,无向
struct Edge
{
    int to,next;
    bool cut;//是否是桥标记
} edge[maxm];
int head[maxn],tot;
int Low[maxn],DFN[maxn],Stack[maxn],Belong[maxn];
int Index,top;
int block;//边双连通块数
bool instack[maxn];
int bridge;//桥的数目
void addedge(int u,int v)
{
    edge[tot].to=v;
    edge[tot].next=head[u];
    edge[tot].cut=false;
    head[u]=tot++;
}
void Tarjan(int u,int pre)
{
    int v;
    Low[u]=DFN[u]=++Index;
    Stack[top++]=u;
    instack[u]=true;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        v=edge[i].to;
        if(v == pre) continue;
        if(!DFN[v])
        {
            Tarjan(v,u);
            if(Low[u]>Low[v]) Low[u]=Low[v];
            if(Low[v]>DFN[u])
            {
                bridge ++;
                edge[i].cut = true;
                edge[i^1].cut = true;
            }
        }
        else if(instack[v]&&Low[u]>DFN[v])
            Low[u]=DFN[v];
    }
    if(Low[u]==DFN[u])
    {
        block++;
        do
        {
            v=Stack[--top];
            instack[v]=false;
            Belong[v]=block;
        }
        while(v!=u);
    }
}
void init()
{
    tot=0;
    memset(head,-1,sizeof(head));
}
int du[maxn];//缩点后形成树,每个点的度数
void solve(int n)
{
    memset(DFN,0,sizeof(DFN));
    memset(instack,false,sizeof(instack));
    Index=top=block=0;
    Tarjan(1,0);
    int res=0;
    memset(du,0,sizeof(du));
    for(int i=1; i<=n; i++)
        for(int j=head[i]; j!=-1; j=edge[j].next)
            if(edge[j].cut) du[Belong[i]]++;
    for(int i=1; i<=block; i++)
        if(du[i]==1)
            res++;//找叶子节点个数为res,构造边双连通图需要加边(res+1)/2
    printf("%d\n",(res+1)/2);
}
int shuru()
{
    int sum=0;
    char ch;
    while((ch=getchar())<='0'||ch>='9');sum=ch-'0';
    while((ch=getchar())>='0'&&ch<='9') sum=sum*10+ch-'0';
    return sum;
}
int main()
{
    //freopen("1.txt","r",stdin);
    int n,m,u,v;
    while(scanf("%d%d",&n,&m)==2)
    {
        init();
        while(m--)
        {
            //scanf("%d%d",&u,&v);
            u=shuru();
            v=shuru();
            addedge(u,v);
            addedge(v,u);
        }
        solve(n);
    }
    return 0;
}
时间: 2024-10-14 22:51:00

【组队赛#9】USACO 2006 January Bronze的相关文章

USACO JAN 2012 Bronze

Problem 1: Gifts [Kalki Seksaria and Brian Dean, 2012] Farmer John wants to give gifts to his N (1 <= N <= 1000) cows, using his total budget of B (1 <= B <= 1,000,000,000) units of money. Cow i requests a gift with a price of P(i) units, and

USACO·2012·Feb Bronze &amp;&amp; 2009·Open Gold

Rope Folding [Brian Dean, 2012] 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Farmer John has a long rope of length L (1 <= L <= 10,000) that he uses for various tasks around his farm. The rope has N knots tied into it at various distinct locations (1 <= N <=

USACO 2017 January Platinum

因为之前忘做了,赶紧补上. T1.Promotion Counting 题目大意:给定一个以1为根的N个节点的树(N<=100,000),每个节点有一个权值,对于每个节点求出权值比它大的子孙的个数. 思路:肯定先要求出dfs序,首先无脑想到主席树,后来发现只要按权值从大到小处理就不用那么麻烦了. #include<cstdio> #include<algorithm> using namespace std; char B[1<<26],*S=B,C;int X;

【BZOJ】【1662】/【POJ】【3252】 【USACO 2006 Nov】Round Number

数位DP 同上一题Windy数 预处理求个组合数 然后同样的方法,这次是记录一下0和1的个数然后搞搞 Orz cxlove 1 /************************************************************** 2 Problem: 1662 3 User: Tunix 4 Language: C++ 5 Result: Accepted 6 Time:0 ms 7 Memory:1280 kb 8 **************************

[Poj3261] [Bzoj1717] [后缀数组论文例题,USACO 2006 December Gold] Milk Patterns [后缀数组可重叠的k次最长重复子串]

和上一题(POJ1743,上一篇博客)相似,只是二分的判断条件是:是否存在一段后缀的个数不小于k 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <cstring> 6 #include <cmath> 7 #include <ctime> 8 #include <map&

USACO 2006 November Gold

POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include <vector> #inc

POJ 3261 USACO 2006 December Gold Milk Patterns

题目大意:给出一个字符串,求出出现过k次以上的最长的子串(可重叠). 思路:现弄出来sa数组和height数组,之后就是判断每个长度为k的height数组的区间中最小的数字的最大值了.为什么好多人都二分了?这只要单调队列扫一次就行了啊.. CODE: #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #def

USACO 2006 NOV Corn Fields

题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't b

BZOJ 1717 Usaco 2006 Dec 产奶模式

1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1557  Solved: 847[Submit][Status][Discuss] Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". John的牛奶按质量可以被赋予一个0到10000