多校3


Work

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
   
   
It’s an interesting experience to move from ICPC to work, end my college life and start a brand new journey in company. As is known to all, every stuff in a company has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B. Now, give you the relation of a company, can you calculate how many people manage k people.
 

Input
   
   
There are multiple test cases. Each test case begins with two integers n and k, n indicates the number of stuff of the company. Each of the following n-1 lines has two integers A and B, means A is the direct leader of B. 1 <= n <= 100 , 0 <= k < n 1 <= A, B <= n
 

Output
   
   
For each test case, output the answer as described above.
 

Sample Input
   
   
7 2 1 2 1 3 2 4 2 5 3 6 3 7
 

Sample Output
   
   
2

题意:数据很小,直接暴力
code:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

vector<int >vec[10000];
struct ode{
int a,b;
}node[10000];

bool cmp(ode A,ode B)
{
    if(A.a==B.a)
        return A.b<B.b;
    return A.a<B.a;
}

int main()
{
    //freopen("i.txt","r",stdin);
   int n,k,a,b;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        for(int i=0;i<=n;i++)
            vec[i].clear();
        for(int i=0;i<n-1;i++)
            scanf("%d%d",&node[i].a,&node[i].b);

        sort(node,node+(n-1),cmp);
        for(int i=0;i<n-1;i++)
        {
            a=node[i].a;
            b=node[i].b;
            vec[a].push_back(b);
            for(int j=1;j<=n;j++)
            {
                int dd=vec[j].size();
                for(int k=0;k<dd;k++)
                {
                    if(vec[j][k]==a)
                       vec[j].push_back(b);
                }
            }
        }
        int ans=0;
       for(int i=1;i<=n;i++)
       {
           if(vec[i].size()==k)
            ans++;
       }
        printf("%d\n",ans);
    }
    return 0;
}

RGCDQ

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
   
   
Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (Li<jR)
 

Input
   
   
There are multiple queries. In the first line of the input file there is an integer T indicates the number of queries. In the next T lines, each line contains L, R which is mentioned above. All input items are integers. 1<= T <= 1000000 2<=L < R<=1000000
 

Output
   
   
For each query,output the answer in a single line. See the sample for more details.
 

Sample Input
   
   
2 2 3 3 5
 

Sample Output
   
   
1 1


code:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
int a[maxn],b[maxn][15];
int GCD(int n,int m)
{
    if(n<m)
        swap(n,m);
    int r;
    while(m)
    {
        r=n%m;
        n=m;
        m=r;
    }
    return n;
}
int main()
{
    for(int i=2; i<=maxn-5; i++)
    {
        if(!a[i])
        {
            for(int j=i; j<=maxn-5; j+=i)
                a[j]++;
        }
    }
    for(int i=2;i<=maxn-5;i++)
    {
        for(int j=1;j<=9;j++)
            b[i][j]=b[i-1][j];
        b[i][a[i]]+=1;
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        int c[15],len=0;
        for(int i=1;i<=9;i++)
            if(b[m][i]-b[n-1][i]>0)
            {
                for(int j=0;j<min(2,b[m][i]-b[n-1][i]);j++)
                    c[len++]=i;
            }
        int Max=-1;
        for(int i=0;i<len;i++)
        {
            for(int j=i+1;j<len;j++)
                Max=max(GCD(c[i],c[j]),Max);
        }
        printf("%d\n",Max);
    }
    return 0;
}

Painter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
   
   
Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day, he got stuck in rut and the ideas dry up, he took out a drawing board and began to draw casually. Imagine the board is a rectangle, consists of several square grids. He drew diagonally, so there are two kinds of draws, one is like ‘\’ , the other is like ‘/’. In each draw he choose arbitrary number of grids to draw. He always drew the first kind in red color, and drew the other kind in blue color, when a grid is drew by both red and blue, it becomes green. A grid will never be drew by the same color more than one time. Now give you the ultimate state of the board, can you calculate the minimum time of draws to reach this state.
 

Input
   
   
The first line is an integer T describe the number of test cases. Each test case begins with an integer number n describe the number of rows of the drawing board. Then n lines of string consist of ‘R’ ‘B’ ‘G’ and ‘.’ of the same length. ‘.’ means the grid has not been drawn. 1<=n<=50 The number of column of the rectangle is also less than 50. Output Output an integer as described in the problem description.
 

Output
   
   
Output an integer as described in the problem description.
 

Sample Input
   
   
2 4 RR.B .RG. .BRR B..R 4 RRBB RGGB BGGR BBRR
 

Sample Output
   
   
3 6

题意:每点遍历,将在同一条直线上的颜色一层层“刮掉”,
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 50 + 5;
char str[maxn][maxn];
int n,m;
void okR(int x,int y)
{
    while(x<n&&y<m&&str[x][y]!='B'&&str[x][y]!='.')
        //while(x<n&&y<m&&str[x][y]!='B')
    {
        if(str[x][y]=='R')
            str[x][y]='.';
        if(str[x][y]=='G')
            str[x][y]='B';
        x++;
        y++;
    }
}
void okB(int x,int y)
{
    while(x<n&&y>=0&&str[x][y]!='R'&&str[x][y]!='.')
    {
        if(str[x][y]=='B')
            str[x][y]='.';
        if(str[x][y]=='G')
            str[x][y]='R';
        x++;
        y--;
    }
}
void okG(int x,int y)
{
    str[x][y]='R';
    okR(x,y);
    str[x][y]='B';
    okB(x,y);
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%s",str[i]);

        m=strlen(str[0]);

        int sum=0;

        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
                if(str[i][j]=='R')
                {
                    okR(i,j);
                    sum++;
                }
                else if(str[i][j]=='B')
                {
                    okB(i,j);
                    sum++;
                }
                else if(str[i][j]=='G')
                {
                   // printf("i= %d ,j= %d,str[i][j]=%c\n",i,j,str[i][j]);
                    okG(i,j);

                    sum+=2;
                }
        }
        printf("%d\n",sum);
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值