• 9.28校内训练赛


    gym 101192 F. Stone, grass and fire
    http://codeforces.com/gym/101192/problem/F

    Farmer Lyosha owns a rectangular field. The field has n rows and m columns. Field cells positions are denoted by pairs of numbers (i, j), where i is the row index and j is the column index. Each cell of the field has either grass (denoted by character '.’) or stone (denoted by character 'X’).

    Disasters happen, and Lyosha's field is on fire. The fire has started in different cells. There are k fire sources. The i-th fire source has started in grass cell (xi, yi) and it will burn for ci seconds. Each second the fire spreads from an already burning cell to adjacent cells that have a common edge with the burning cell. If in current cell fire will burn for c second, then this fire will burn for c - 1 seconds in adjacent cells. The fire did not spread to adjacent cells, if it will burn for zero seconds in current cell.

    Assume that all fire sources are independent. All fire sources have distinct coordinates. Stone does not burn.

    Lyosha is very eager to know how many grass cells are going to burn down.

    Input

    The first input line contains three integer numbers — n, m, k — which denote the field size and the number of fire sources. Following that are n lines describing the field, each line has m characters. The j-th character in the i-th line denotes type of the (i, j) cell. The next k lines each contain three integer numbers xi, yi, ci that describe the i-th fire source.

    1 ≤ N, M ≤ 500
    0 ≤ K ≤ N × M
    1 ≤ xi ≤ N
    1 ≤ yi ≤ M
    1 ≤ ci ≤ 109
    Output

    Output one integer number: the number of grass cells that will burn down.

    Example
    Input
    4 5 2
    .X...
    .X.X.
    .X.X.
    ...X.
    1 3 1
    3 3 4
    Output
    9
    写了个bfs,但可能循环250000次,超了,最好用dfs。

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}},n,m,k;
    char a[505][505];
    int vis[505][505],x,y,t,cnt=0;
    void dfs(int u,int v,int t)
    { 
        if(t<0) return ;
        vis[u][v]=max(vis[u][v],t);
        if(t<vis[u][v]) return ;
        for(int i=0;i<4;i++)
        {
            int x=u+dir[i][0];
            int y=v+dir[i][1];
            if(x>=1 && x<=n && y>=1 && y<=m && a[x][y]=='.') dfs(x,y,t-1);
        }
    }
    int main()
    {
        scanf("%d%d%d",&n,&m,&k);
        memset(vis,-1,sizeof(vis));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                cin>>a[i][j];
        while(k--)
        {
            scanf("%d%d%d",&x,&y,&t);
            dfs(x,y,t);
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                cnt+=vis[i][j]>=0?1:0;
        printf("%d
    ",cnt);
        return 0;
    }
    gym 101446 F. Tree and Strings
    https://i.cnblogs.com/EditPosts.aspx?postid=7614867

    A city consists of n junctions connected by n - 1 bidirectional roads so that any junction is reachable from any other junction by travelling the roads. Each road is colored by one of 26 colors, represented by lowercase English letters between 'a' and 'z'.

    For each pair of junctions u and v there is only one simple path connecting them. Let us define the signature of this path as the string of letters that is obtained by writing down the letters corresponding to edges in the path in this order. Note that the signature of the path from v to u is the same as reversed signature of the path from u to v.

    Given signatures of all different paths between junctions, reconstruct the road structure of the city.

    Input

    The first line of the input contains one integer n (2 ≤ n ≤ 100) — number of junctions in the city. Next lines contain signatures of paths. i-th of those lines contain two space-separated integers ui, vi (1 ≤ ui, vi ≤ n) and a string of lowercase Latin letters — the signature of the path from ui to vi.

    You may assume that exactly one of two paths (ui, vi) and (vi, ui) is represented in the input data. It is guaranteed that there is at least one possible solution for the given data.

    Output

    Print n - 1 line. On j-th of those lines print aj bj cj, where aj, bj are the numbers of junctions connected by the road j, and cj is a letter that describes the color of the road. Roads can be listed in any order, as well as endpoints of any particular road.

    Examples
    Input
    3
    1 2 a
    1 3 b
    2 3 ab
    Output
    1 2 a
    1 3 b
    Input
    2
    2 1 a
    Output
    2 1 a
    英语是个硬伤,题目的意思是找n-1条路可以构成一颗树,使得任何两点都可以到达。因此,最小生成树就行了。
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    struct point
    {
        int u,v;
        string s;
        friend bool operator<(const point &a,const point &b)
        {
            return (a.s).size()<(b.s).size();
        }
    }node[4960];
    int n,f[101],k;
    int find(int x)
    {
        return f[x]==x?f[x]:find(f[x]);
    }
    void krukscal()
    {
        int x,y;
        for(int i=0;i<=k;i++) f[i]=i;
        for(int i=0;i<n;i++)
        {
            x=find(node[i].u);
            y=find(node[i].v);
            if(x!=y)
            {
                printf("%d %d ",node[i].u,node[i].v);
                cout<<node[i].s<<endl;
                f[min(x,y)]=max(x,y);
                if(--k==1) break;
            }
        }
    }
    int main()
    {
        scanf("%d",&n);
        k=n;
        n=n*(n-1)/2;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&node[i].u,&node[i].v);
            cin>>node[i].s;
        }
        sort(node,node+n);
        krukscal();
        return 0;
    }
    gym 100495 K. Wolf and sheep

    A sheep lives on an infinite field. The sheep wants to eat some grass. Grass only exists in one place. That place is a circle defined by a center point (Gx, Gy) and a radius Gr.

    The sheep would gladly eat all the grass. But if you read the title of this task you noticed that there is also a wolf on that field. The wolf wants to eat the sheep, but we don't want that to happen.

    The wolf is tied to a pole at position (Wx, Wy) with a rope of length Wr.

    Find the area of grass that the sheep can eat without being eaten by the wolf. We can assume that the sheep starts in a safe location.

    Input

    The first line contains the number of test cases T (1 ≤ T ≤ 10000).

    Each test case consists of 2 lines. The first line contains integers Gx, Gy and Gr. The second line contains integers Wx, Wy and Wr. ( - 105 ≤ Gx, Gy, Wx, Wy ≤ 105, 1 ≤ Gr, Wr ≤ 105)

    Output

    For each test case output one line containing “Case #tc: A”, where tc is the number of the test case (starting from 1) and A is the area of grass that the sheep can eat safely with a maximum absolute or relative error of 10 - 6.

    Examples
    Input
    2
    0 0 5
    0 10 5
    0 0 5
    5 0 5
    Output
    Case #1: 78.53981634
    Case #2: 47.83057387
    草的面积减去公共部分面积(恶心)

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    double xl,x2,yl,y2,rl,r2;
    int n,cas=0;
    double dis()
    {
        return sqrt((xl-x2)*(xl-x2) + (yl-y2)*(yl-y2));
    }
    void solve()
    {
        printf("Case #%d: ",++cas);
        double dist=dis();
        if(dist>=(rl+r2)) printf("%.8lf
    ",pi*rl*rl);
        else if((dist+rl)<=r2) printf("0.00000000
    ");
        else if((dist+r2)<=rl) printf("%.8lf
    ",pi*(rl*rl-r2*r2));
        else
        {
            double al=acos((rl*rl+dist*dist-r2*r2)/(2.0*dist*rl));
            double bl=acos((r2*r2+dist*dist-rl*rl)/(2.0*dist*r2));
            printf("%.8lf
    ",pi*rl*rl-((al*rl*rl + bl*r2*r2) - (((sin(2.0*al)*rl*rl)+(sin(2.0*bl)*r2*r2))/2.0)));
        }
    }
    int main()
    {
        scanf("%d",&n);
        while(n--)
        {
            scanf("%lf%lf%lf%lf%lf%lf",&xl,&yl,&rl,&x2,&y2,&r2);
            solve();
        }
    }
    gym 100495 D. Modulo maths
    http://codeforces.com/gym/100495/problem/D

    Birute loves modular arithmetics, but hates long problem statements.

    Given n, find f(n).

    Input

    The first line contains the number of test cases T (T ≤ 50). In the following T lines there are integer values of number n (1 ≤ n ≤ 10007).

    Output

    For each test case output one line containing “Case #tc: num”, where tc is the number of the test case (starting from 1) and num is the value of f(n).

    Examples
    Input
    2
    1
    2
    Output
    Case #1: 1
    Case #2: 0
    Note

    Fun fact: 1 is neither prime nor composite number.

    拼手速题目

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int a[10009];
    void get()
    {
        memset(a,0,sizeof(a));
        a[1]=1;
        for(int i=2;i<=10007;i++)
        {
            if(a[i]) continue;
            for(int j=2;j*i<=10007;j++)
                a[j*i]=1;
        }
    }
    ll pow_q(ll x,ll y,ll z)
    {
        ll ans=1;
        while(y)
        {
            if(y&1) ans=ans*x%z;
            y>>=1;
            x=x*x%z;
        }
        return ans;
    }
    int main()
    {
        get();
        ll t,n;
        scanf("%lld",&t);
        ll k=t;
        while(t--)
        {
            scanf("%lld",&n);
            printf("Case #%lld: ",k-t);
            if(n==1){printf("1
    ");continue;}
            else if(a[n]==0)
            {
                printf("%lld
    ",pow_q(2,n-1,n));
            }
            else printf("%lld
    ",(n-1)*(n-1)%n);
        }
        return 0;
    }
    //方法二:
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int t,n,k;
    int main()
    {
        scanf("%d",&t);
        k=t;
        while(t--)
        {
            scanf("%d",&n);
            printf("Case #%d: ",k-t);
            puts(n==2?"0":"1");
        }
        return 0;
    }
    gym 101059 B. Shift and Push
    http://codeforces.com/gym/101059/problem/B

    Given two equally sized arrays A and B of size N. A is empty and B has some values.

    You need to fill A with an element X such that X belongs to B.

    The only operations allowed are:

    1. Copy B[i] to A[i].

    2. Cyclic shift B by 1 to the the right.

    You need to minimise the number of operations.

    Input

    The first line contains a single positive integer N(1 ≤ N ≤ 106), denoting the size of the arrays.

    Next line contains N space separated positive integers denoting the elements of the array B(1 ≤ B[i] ≤ 105).

    Output

    Output a single integer, denoting the minimum number of operations required.

    Examples
    Input
    3
    1 2 3
    Output
    5
    Input
    6
    1 1 2 2 3 3
    Output
    10
    Note

    In the first test case:

    We can have 5 steps as: fill first element, shift, fill second element, shift, fill third element.

    Initially, A = [_, _, _], B = [1, 2, 3]

    After step 1, A = [1, _, _], B = [1, 2, 3]

    After step 2, A = [1, _, _], B = [3, 1, 2]

    After step 3, A = [1, 1, _], B = [3, 1, 2]

    After step 4, A = [1, 1, _], B = [2, 3, 1]

    After step 5, A = [1, 1, 1], B = [2, 3, 1]

    自己理解错题了,以为是只能从首元素开始复制移动,因此只能针对一种情况,题目说可以任意,这样用数组记录下间隔,更新最大值就可以了。哎,惨。。。。。。。

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int a[1000007],b[100005][5],n;
    int main()
    {
        scanf("%d",&n);
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(b[a[i]][0]==0) b[a[i]][1]=b[a[i]][2]=b[a[i]][3]=i;
            else b[a[i]][2]=b[a[i]][3],b[a[i]][3]=i,b[a[i]][4]=max(b[a[i]][4],i-b[a[i]][2]-1);
            b[a[i]][0]++;
        }
        int ans=INF;
        for(int i=1;i<=n;i++)
        {
            b[a[i]][4]=max(b[a[i]][4],n-b[a[i]][3]+b[a[i]][1]-1);
            ans=min(ans,n+b[a[i]][4]);
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    Git SSH Key 生成步骤
    Mac终端(Terminal)自定义颜色,字体,背景
    MAC进入文件夹快捷键
    在Terminal中,如何打开Finder,并显示当前的目录
    mac文件夹怎么重命名?苹果电脑文件夹重命名快捷键
    如何在Mac OS X中开启或关闭显示隐藏文件命令
    怎样将二个路由进行桥接的方法
    关于apache access log 统计的那些事儿
    aaaa
    CodeForces463C Gargari and Bishops(贪心)
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7614867.html
Copyright © 2020-2023  润新知