2014多校第五场

50 篇文章 0 订阅
27 篇文章 0 订阅

刚开始出的两个题还挺快的,结果后来就掉的找不找了。。。。最后一个题,调了半天结果发现数组访问越界,无语。。。

Apple Tree

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


Problem Description
  
  
I’ve bought an orchard and decide to plant some apple trees on it. The orchard seems like an N * M two-dimensional map. In each grid, I can either plant an apple tree to get one apple or fertilize the soil to speed up its neighbors’ production. When a grid is fertilized, the grid itself doesn’t produce apples but the number of apples of its four neighbor trees will double (if it exists). For example, an apple tree locates on (x, y), and (x - 1, y), (x, y - 1) are fertilized while (x + 1, y), (x, y + 1) are not, then I can get four apples from (x, y). Now, I am wondering how many apples I can get at most in the whole orchard?
 

Input
  
  
The input contains multiple test cases. The number of test cases T (T<=100) occurs in the first line of input. For each test case, two integers N, M (1<=N, M<=100) are given in a line, which denote the size of the map.
 

Output
  
  
For each test case, you should output the maximum number of apples I can obtain.
 

Sample Input
  
  
2 2 2 3 3
 

Sample Output
  
  
8 32

#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int a[110][110];
int main()
{
//    freopen("in.txt","r",stdin);
    int t,n,m;
    cin>>t;
    while(t--)
    {
        int ans=0;
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if((i+j)%2==0)
                    a[i][j]=1;
                else a[i][j]=0;
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(a[i][j])
                {
                    if(i!=0)    a[i][j]*=2;
                    if(j!=0)    a[i][j]*=2;
                    if(i!=n-1)  a[i][j]*=2;
                    if(j!=m-1)  a[i][j]*=2;
                    ans+=a[i][j];
                }

            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Series 1

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


Problem Description
  
  
Let A be an integral series {A 1, A 2, . . . , A n}. The zero-order series of A is A itself. The first-order series of A is {B 1, B 2, . . . , B n-1},where B i = A i+1 - A i. The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1). Obviously, the (n - 1)th-order series of A is a single integer. Given A, figure out that integer.
 

Input
  
  
The input consists of several test cases. The first line of input gives the number of test cases T (T<=10). For each test case: The first line contains a single integer n(1<=n<=3000), which denotes the length of series A. The second line consists of n integers, describing A 1, A 2, . . . , A n. (0<=A i<=10 5)
 

Output
  
  
For each test case, output the required integer in a line.
 

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

Sample Output
  
  
0 -5

二项式定理系数,java大数搞定

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner read=new Scanner(System.in);
        int T;
        int N;
        BigInteger C[]=new BigInteger[3010];
        BigInteger a[]=new BigInteger[3010];
        //System.out.println("11111");
        T=read.nextInt();
        while(T-->0){
            N=read.nextInt();
            for(int i=1;i<=N;i++)
                a[i]=read.nextBigInteger();
            C[0]=C[N]=BigInteger.ONE;
            for(int i=1;i<N;i++){
                BigInteger tmp=(BigInteger.valueOf(N-1).subtract(BigInteger.valueOf(i)).add(BigInteger.ONE));
                C[i]=(C[i-1].multiply(tmp)).divide(BigInteger.valueOf(i));
            }
            
            BigInteger ans=new BigInteger("0");
            for(int i=N;i>=1;i--){
                if(i%2==1){
                    if(N%2==1){
                        ans=ans.add(a[i].multiply(C[i-1]));
                    }
                    else {
                        ans=ans.subtract(a[i].multiply(C[i-1]));
                    }
                    
                }
                else {
                    if(N%2==1){
                        ans=ans.subtract(a[i].multiply(C[i-1]));
                    }
                    else {
                        ans=ans.add(a[i].multiply(C[i-1]));
                    }
                }
            }
            System.out.println(ans);
        }

    }

}

Fighting the Landlords

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 180    Accepted Submission(s): 76


Problem Description
  
  
Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 17. The Landlord wins if he/she has no cards left, and the farmer team wins if either of the Farmer have no cards left. The game uses the concept of hands, and some fundamental rules are used to compare the cards. For convenience, here we only consider the following categories of cards: 1.Solo: a single card. The priority is: Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. It’s the basic rank of cards. 2.Pair : two matching cards of equal rank (e.g. 3-3, 4-4, 2-2 etc.). Note that the two Jokers cannot form a Pair (it’s another category of cards). The comparison is based on the rank of Solo, where 2-2 is the highest, A-A comes second, and 3-3 is the lowest. 3.Trio: three cards of the same rank (e.g. 3-3-3, J-J-J etc.). The priority is similar to the two categories above: 2-2-2 > A-A-A > K-K-K > . . . > 3-3-3. 4.Trio-Solo: three cards of the same rank with a Solo as the kicker. Note that the Solo and the Trio should be different rank of cards (e.g. 3-3-3-A, 4-4-4-X etc.). Here, the Kicker’s rank is irrelevant to the comparison, and the Trio’s rank determines the priority. For example, 4-4-4-3 > 3-3-3-2. 5.Trio-Pair : three cards of the same rank with a Pair as the kicker (e.g. 3-3- 3-2-2, J-J-J-Q-Q etc.). The comparison is as the same as Trio-Solo, where the Trio is the only factor to be considered. For example,4-4-4-5-5 > 3-3-3-2-2. Note again, that two jokers cannot form a Pair. 6.Four-Dual: four cards of the same rank with two cards as the kicker. Here, it’s allowed for the two kickers to share the same rank. The four same cards dominates the comparison: 5-5-5-5-3-4 > 4-4-4-4-2-2. In the categories above, a player can only beat the prior hand using of the same category but not the others. For example, only a prior Solo can beat a Solo while a Pair cannot. But there’re exceptions: 7.Nuke: X-Y (JOKER-joker). It can beat everything in the game. 8.Bomb: 4 cards of the same rank. It can beat any other category except Nuke or another Bomb with a higher rank. The rank of Bombs follows the rank of individual cards: 2-2-2-2 is the highest and 3-3-3-3 is the lowest. Given the cards of both yours and the next player’s, please judge whether you have a way to play a hand of cards that the next player cannot beat you in this round. If you no longer have cards after playing, we consider that he cannot beat you either. You may see the sample for more details.
 

Input
  
  
The input contains several test cases. The number of test cases T (T<=20) occurs in the first line of input. Each test case consists of two lines. Both of them contain a string indicating your cards and the next player’s, respectively. The length of each string doesn’t exceed 17, and each single card will occur at most 4 times totally on two players’ hands except that the two Jokers each occurs only once.
 

Output
  
  
For each test case, output Yes if you can reach your goal, otherwise output No.
 

Sample Input
  
  
4 33A 2 33A 22 33 22 5559T 9993
 

Sample Output
  
  
Yes No Yes Yes


斗地主,蛋疼的模拟题

#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
char a[25],b[25];
int cnt1[25],cnt2[25];
int main()
{
    int T,len1,len2;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s%s",a,b);
        len1=strlen(a);
        len2=strlen(b);
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));
        for(int i=0;i<len1;i++)
        {
            if(a[i]>='3'&&a[i]<='9') cnt1[a[i]-'0']++;
            else if(a[i]=='T') cnt1[10]++;
            else if(a[i]=='J') cnt1[11]++;
            else if(a[i]=='Q') cnt1[12]++;
            else if(a[i]=='K') cnt1[13]++;
            else if(a[i]=='A') cnt1[14]++;
            else if(a[i]=='2') cnt1[15]++;
            else if(a[i]=='X') cnt1[16]++;
            else if(a[i]=='Y') cnt1[17]++;
        }
        for(int i=0;i<len2;i++)
        {
            if(b[i]>='3'&&b[i]<='9') cnt2[b[i]-'0']++;
            else if(b[i]=='T') cnt2[10]++;
            else if(b[i]=='J') cnt2[11]++;
            else if(b[i]=='Q') cnt2[12]++;
            else if(b[i]=='K') cnt2[13]++;
            else if(b[i]=='A') cnt2[14]++;
            else if(b[i]=='2') cnt2[15]++;
            else if(b[i]=='X') cnt2[16]++;
            else if(b[i]=='Y') cnt2[17]++;
        }
        if(cnt1[17]&&cnt1[16]) {    printf("Yes\n"); continue;    }
        int mark=0,mark1=0,mark2=0,mark0=0;
        int pos1=0,pos2=0;
        //solo
        for(int i=20;i>=0;i--)
        {
            if(cnt1[i])
            {
                pos1=i;break;
            }
        }
        for(int i=20;i>=0;i--)
            if(cnt2[i])
            {
                pos2=i;break;
            }
        if(pos1&&pos1>=pos2)
            mark=1;
        if(len1==1)
            mark0=1;

        //pair
        pos1=pos2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]>=2)
            {
                pos1=i;break;
            }
        for(int i=20;i>=0;i--)
            if(cnt2[i]>=2)
            {
                pos2=i;break;
            }
        if(pos1&&pos1>=pos2)
            mark=1;
        if(pos1&&len1==2)
            mark0=1;
        //trio
        pos1=pos2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]>=3)
            {
                pos1=i;break;
            }
        for(int i=20;i>=0;i--)
            if(cnt2[i]>=3)
            {
                pos2=i;
                break;
            }
        if(pos1&&pos1>=pos2)
            mark=1;
        if(pos1&&len1==3)
            mark0=1;

        //trio-solo
        pos1=pos2=0;
        mark1=mark2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]>=3)
            {
                if(len1-cnt1[i]>=1) mark1=1;
                pos1=i;break;
            }
        for(int i=20;i>=0;i--)
            if(cnt2[i]>=3)
            {
                if(len2-cnt2[i]>=1)
                {
                    mark2=1;
                    pos2=i;break;
                }
            }
        if(pos1&&mark1&&pos1>=pos2)
            mark=1;
        if(pos1&&mark1&&len1==4)
            mark0=1;

        //trio-pair
        pos1=pos2=0;
        mark1=mark2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]>=3)
            {
                for(int k=20;k>=0;k--)
                {
                    if(k!=i&&cnt1[k]>=2)
                    {
                        pos1=i;
                        mark1=1;
                        break;
                    }
                }
                break;
            }
        for(int i=20;i>=0;i--)
            if(cnt2[i]>=3)
            {
                for(int k=20;k>=0;k--)
                {
                    if(k!=i&&cnt2[k]>=2)
                    {
                        mark2=1;
                        pos2=i;
                        break;
                    }
                }
                break;
            }
        if(pos1&&mark1&&pos1>=pos2)
            mark=1;
        if(pos1!=0&&mark1&&len1==5)
            mark0=1;

        //4+2
        pos1=pos2=0;
        mark1=mark2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]==4)
            {
                if(len1-cnt1[i]>=2) mark1=1;
                pos1=i;break;
            }
        for(int i=20;i>=0;i--)
            if(cnt2[i]==4)
            {
                if(len2-cnt2[i]>=2)
                {
                    mark2=1;
                    pos2=i;break;
                }
            }
        if(pos1&&mark1&&pos1>=pos2)
            mark=1;
        if(pos1!=0&&mark1&&len1==6)
            mark0=1;

        //Bomb
        pos1=pos2=0;
        mark1=mark2=0;
        for(int i=20;i>=0;i--)
            if(cnt1[i]==4)
                pos1=i;break;
            
        for(int i=20;i>=0;i--)
            if(cnt2[i]==4)
                pos2=i;break;
        if(pos1&&pos1>=pos2)
            mark=1;
        else if(pos1<pos2)
            mark=0;
        if(pos1!=0&&len1==4)
            mark0=1;
        if(cnt2[16]&&cnt2[17])
            mark=0;
        if(mark||mark0)
            printf("Yes\n");
        else printf("No\n");

    }
    return 0;
}

F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Room and Moor

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 109    Accepted Submission(s): 22


Problem Description
PM Room defines a sequence A = {A 1, A 2,..., A N}, each of which is either 0 or 1. In order to beat him, programmer Moor has to construct another sequence B = {B 1, B 2,... , B N} of the same length, which satisfies that:

 

Input
The input consists of multiple test cases. The number of test cases T(T<=100) occurs in the first line of input.

For each test case:
The first line contains a single integer N (1<=N<=100000), which denotes the length of A and B.
The second line consists of N integers, where the ith denotes A i.
 

Output
Output the minimal f (A, B) when B is optimal and round it to 6 decimals.
 

Sample Input
      
      
4 9 1 1 1 1 1 0 0 1 1 9 1 1 0 0 1 1 1 1 1 4 0 0 1 1 4 0 1 1 1
 

Sample Output
      
      
1.428571 1.000000 0.000000 0.000000


这个题比赛的时候没搞出来。。。

思路:首先剔除为首的0,和末尾的1,然后将中间部分成若干段由连续1开头,连续0结尾的各个段落。对于每一段有一个最优的值x=aa+b(a为1的个数,b为0的个数),用栈维护各个段的x值,如果当前x值小于前面一个段的x值,那么就要将两个段合并,

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;
const int maxn = 1e5+5;

int n, a[maxn], l, r;

struct state {
    int p, q;
    double x;
    state (int p, int q) {
        this->p = p;
        this->q = q;
        this->x = p * 1.0 / (p + q);
    }
};

double solve () {
    l = 0; r = n-1;
    while (l < n && a[l] == 0)
        l++;
    while (r >= 0 && a[r] == 1)
        r--;

    if (r <= l)
        return 0;

    bool flag = true;
    int cntp = 0, cntq = 0;
    queue<state> que;

    for (int i = l; i <= r; i++) {
        if (flag && a[i] == 1)
            cntp++;
        else if (flag == false && a[i] == 0)
            cntq++;
        else if (flag == false && a[i] == 1) {
            que.push(state(cntp, cntq));
            cntp = 1;
            flag = true;
        } else {
            cntq = 1;
            flag = false;
        }
    }

    que.push(state(cntp, cntq));

    stack<state> sta;
    while (!que.empty()) {
        state u = que.front();
        que.pop();

        while (!sta.empty() && sta.top().x > u.x) {
            u.p += sta.top().p;
            u.q += sta.top().q;
            u.x = u.p * 1.0 / (u.p + u.q);
            sta.pop();
        }

        sta.push(u);
    }

    double ans = 0;
    while (!sta.empty()) {
        state u = sta.top();    
        sta.pop();
        ans += (pow(1-u.x, 2) * u.p + pow(u.x, 2) * u.q);
    }
    return ans;;
}

int main () {
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d", &a[i]);
        printf("%.6lf\n", solve());
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值