Contest1009 - 华中农业大学第四届程序设计大赛网络同步赛C,H,J

Problem C: The Same Color
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 993  Solved: 595
[Submit][Status][Web Board]
Description


   Diao Yang has many balls with different colors. Today he wants to divide his balls into two groups. But he does not know how to divide. Then Diao Ze gives him a suggestion: first you choose a ball and put it into the first group. Then from the second ball, if the color of the ball is same to the last ball you has chosen, then you put the ball into the other group. Otherwise you put the ball into the same group with the last ball. Diao Yang thinks it is OK.
   Then the problem is, Diao Yang wants to know the product of the number of two groups’ balls. Can you help him?
Input


   The first line contains an integer T, indicating the number of test cases.
   In each test case, there are several lines, each line contains only one string with lowercas, indicating the color of the ball Diao Yang has chosen currently. Diao Yang will stop choosing when the string is equal to “END”. Note that the string “END” does not mean a color.
   You can assume that there are at most 100 lines in each test case and each string has at most 10 letters.
Output


   For each test case, output the answer in a line.
Sample Input
3
yellow
yellow
pink
red
red
green
END
blue
black
purple
purple
END
rose
orange
brown
white
END
Sample Output
9
3
0
HINT

In the first test case, the color of the first group’s balls are yellow, red, green, 3 balls in total. The color of the second group’s balls are yellow, pink, red, 3 balls in total too. So the product is 3×3=9.


   In the second test case, the answer is 3×1=3 and in the third test case the answer is 4×0=0.



代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
char aa[3][15],ch[15],end[]="END";
int a[3],k;
int main()
{
    int n;scanf("%d",&n);
    while (n--)
    {
        a[0]=a[1]=0;k=0;
        while (~scanf("%s",ch))
        {
            if (strcmp(ch,end)==0) break;
            if (a[k])
            {
                bool fafe=false;
                if (strlen(ch)==strlen(aa[k]))
                {
                    fafe=true;
                    for (int i=0;i<strlen(ch);i++)
                    if (ch[i]!=aa[k][i])
                    {
                        fafe=false;
                        break;
                    }
                }
                if (fafe)
                {
                    k=(k+1)%2;
                    strcpy(aa[k],ch);
                    a[k]++;
                }
                else
                {
                    strcpy(aa[k],ch);
                    a[k]++;
                }
            }
            else
            {
                strcpy(aa[k],ch);
                a[k]++;
            }
         
        }
        printf("%d\n",a[0]*a[1]);
    }
    return 0;
}
/**************************************************************
    Problem: 14
    User: team387
    Language: C++
    Result: Accepted
    Time:110 ms
    Memory:1032 kb
***********************************



Problem H: Eat Candy
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1333  Solved: 644
[Submit][Status][Web Board]
Description


   There is a box with infinite volume. At first there are n candies in the box. Then every second you will eat some candies, left half of candies (round down) in the box. Then add k candies into the box. How many candies there are in the box after 109+7 seconds?
Input


   There are multiple test cases. In each test case, there are only one line contains two integers n,k(1≤n,k≤109+7)
Output


    For each test case, output the answer in one line.


Sample Input
4 5
2 3
Sample Output
9
5
HINT


In the first test case:


1st second, 4->2, 2+5 = 7


2nd second, 7->3, 3+5 = 8


3rd second, 8->4, 4+5 = 9


4th second, 9->4, 4+5 = 9





1000000007th            9


So there are 9 candies in the box after 1000000007 seconds.



代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define LL long long
LL n,k;
int main()
{
    while (~scanf("%lld%lld",&n,&k))
    {
        while (1)
        {
            if ((n+1)/2==k) break;
            n/=2;n+=k;
        }
        printf("%lld\n",n);
    }
    return 0;
}
/**************************************************************
    Problem: 19
    User: team387
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1032 kb
***********************************************



Problem J: Arithmetic Sequence
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1804  Solved: 308
[Submit][Status][Web Board]
Description
    Giving a number sequence A with length n, you should choosing m numbers from A(ignore the order) which can form an arithmetic sequence and make m as large as possible.


Input


   There are multiple test cases. In each test case, the first line contains a positive integer n. The second line contains n integers separated by spaces, indicating the number sequence A. All the integers are positive and not more than 2000. The input will end by EOF.
Output


   For each test case, output the maximum  as the answer in one line.
Sample Input
5
1 3 5 7 10
8
4 2 7 11 3 1 9 5
Sample Output
4
6
HINT






   In the first test case, you should choose 1,3,5,7 to form the arithmetic sequence and its length is 4.


   In the second test case, you should choose 1,3,5,7,9,11 and the length is 6.



代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int shu[10010];
bool fafe[2005],guo[2005][2005];
int n,s,ss,lp;
int main()
{
    while (~scanf("%d",&n))
    {
        memset(fafe,false,sizeof(fafe));
        memset(guo,false,sizeof(guo));
        for (int i=0;i<n;i++)
        {
            scanf("%d",&shu[i]);
            fafe[shu[i]]=true;
        }
        sort(shu,shu+n);
        lp=ss=0;s=1;
        for (int i=1;i<=n;i++)
        {
            if (shu[i]!=shu[lp])
            {
                ss=i-lp;
                lp=i;
            }
            s=max(s,ss);
        }
        for (int i=0;i<n;i++)
        {
            if (i&&shu[i]==shu[i-1]) continue;
            for (int j=i+1;j<n;j++)
            {
                if (guo[shu[j]][shu[j-i]]||shu[j]==shu[i]||shu[j]==shu[j-1]) continue;
                ss=2;lp=shu[j]-shu[i];
                guo[shu[j]][lp]=true;
                for (int k=shu[j]+lp;k<2001;k+=lp)
                {
                    if (fafe[k])
                    {
                        guo[k][lp]=true;
                        ss++;
                    }
                    else
                    break;
                }
                s=max(s,ss);
            }
        }
        printf("%d\n",s);
    }
    return 0;
}
/**************************************************************
    Problem: 21
    User: team387
    Language: C++
    Result: Accepted
    Time:268 ms
    Memory:5004 kb
*******************************************************


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值