BestCoder Round #11 (Div. 2) 前三题题解

题目链接:

huangjing

hdu5054 Alice and Bob

思路:

就是(x,y)在两个參考系中的表示演全然一样。那么仅仅可能在这个矩形的中点。。

题目:

Alice and Bob

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 216    Accepted Submission(s): 166

Problem Description

Bob and Alice got separated in the Square, they agreed that if they get separated, they‘ll meet back at the coordinate point (x, y). Unfortunately they forgot to define the origin of coordinates and the coordinate axis direction. Now, Bob in the lower left
corner of the Square, Alice in the upper right corner of the the Square. Bob regards the lower left corner as the origin of coordinates, rightward for positive direction of axis X, upward for positive direction of axis Y. Alice regards the upper right corner
as the origin of coordinates, leftward for positive direction of axis X, downward for positive direction of axis Y. Assuming that Square is a rectangular, length and width size is N * M. As shown in the figure:

Bob and Alice with their own definition of the coordinate system respectively, went to the coordinate point (x, y). Can they meet with each other ?

Note: Bob and Alice before reaching its destination, can not see each other because of some factors (such as buildings, time poor).

Input

There are multiple test cases. Please process till EOF. Each test case only contains four integers : N, M and x, y. The Square size is N * M, and meet in coordinate point (x, y). ( 0 < x < N <= 1000 , 0 < y < M <= 1000 ).

Output

If they can meet with each other, please output "YES". Otherwise, please output "NO".

Sample Input

10 10 5 5
10 10 6 6

Sample Output

YES
NO

Source

BestCoder Round #11 (Div. 2)

Recommend

heyang   |   We have carefully selected several similar problems for you:  5057 5052 5051 5050 5049

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

int  main()
{
    int x,y,n,m;
    while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF)
    {
        if(2*x==n&&2*y==m)
            printf("YES\n");
        else
            printf("NO\n");
    }
  }

hdu 5055 Bob and math problem

题意:

就是给出n个数字,然后要你找到一个满足例如以下条件的数。

(1)这个数是奇数。

(2)这个数是是最大的数。

(3)另一个被cha的点是全部的数字都要用到。我就是0 0 1 被cha了。。我还有益特判这样的情况,都是题目没有读懂啊。。

思路:

贪心的做法,首先看全部的位是否存在基数,假设基数都没有,那么肯定是不存在这样的数的,其次假设有,那么就将最小的基数找出来做各位,然后将全部的位进行排序,然后从低位向高位赋值,那么就得到这个树了,最后推断一下,假设首位为0,那么这个数就是不存在的,由于要求输出全部的位。。

题目:

Bob and math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 643    Accepted Submission(s): 245

Problem Description

Recently, Bob has been thinking about a math problem.

There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer.

This Integer needs to satisfy the following conditions:

  • 1. must be an odd Integer.
  • 2. there is no leading zero.
  • 3. find the biggest one which is satisfied 1, 2.

Example:

There are three Digits: 0, 1, 3. It can constitute six number of Integers. Only "301", "103" is legal, while "130", "310", "013", "031" is illegal. The biggest one of odd Integer is "301".

Input

There are multiple test cases. Please process till EOF.

Each case starts with a line containing an integer N ( 1 <= N <= 100 ).

The second line contains N Digits _1, a_2, a_3, \cdots, a_n. ( 0 \leqwhich indicate the digit $a a_i \leq 9)$.

Output

The output of each test case of a line. If you can constitute an Integer which is satisfied above conditions, please output the biggest one. Otherwise, output "-1" instead.

Sample Input

3
0 1 3
3
5 4 2
3
2 4 6

Sample Output

301
425
-1

Source

BestCoder Round #11 (Div. 2)

Recommend

heyang   |   We have carefully selected several similar problems for you:  5057 5052 5051 5050 5049

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=100+10;
int a[maxn],odd[maxn];
char str[maxn];
int n;

int  main()
{
    int ans,pd;
    while(scanf("%d",&n)!=EOF)
    {
        memset(str,0,sizeof(str));
        int cnt=0,first=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%2)
               odd[++cnt]=a[i];
        }
        sort(odd+1,odd+1+cnt);
        sort(a+1,a+1+n);
        int ly=n-1;
        if(cnt==0)
            puts("-1");
        else
        {
            str[ly]=odd[1]+'0';
            ly--;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==odd[1]&&!first)
                {
                    first=1;
                    continue;
                }
                else
                {
                    str[ly]=a[i]+'0';
                    ly--;
                }
            }
            if(str[0]=='0')
                puts("-1");
            else
                {
                    for(int i=0;i<=n-1;i++)
                        printf("%c",str[i]);
                    printf("\n");
                }
        }
    }
    return 0;
}

hdu 5056 Boring count

题意:

给出一个字符串,然后求出它全部的子串中每一个字母的数目不超过k个的全部的子串的数目。。

思路:

枚举每一个字符,然后以每一个字符i为子串末尾,然后得到的满足条件的子串的最长长度。。就算字母同样,仅仅要位置不同样就算不同的。。2333333333,那么思路就是维护一个起点st,每当第i个字符的数目大于k后,那么就将st后移,同一时候将当前的每一个cnt[i]减减,直到移动到与i同样的字符你,那么从st到i这段字符就满足条件了。。。认为这个思路真是奇妙。。。。

题目;

Boring count

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 451    Accepted Submission(s): 169

Problem Description

You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.

Input

In the first line there is an integer T , indicates the number of test cases.

For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.

[Technical Specification]

1<=T<= 100

1 <= the length of S <= 100000

1 <= K <= 100000

Output

For each case, output a line contains the answer.

Sample Input

3
abc
1
abcabc
1
abcabc
2

Sample Output

6
15
21

Source

BestCoder Round #11 (Div. 2)

Recommend

heyang   |   We have carefully selected several similar problems for you:  5057 5052 5051 5050 5049

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const  int maxn=100000+10;
char str[maxn];
int cnt[28];

int main()
{
    ll ans;
    int t,st,k,ly;
    scanf("%d",&t);
    while(t--)
    {
        memset(cnt,0,sizeof(cnt));
        st=ans=0;
        scanf("%s%d",str,&k);
        for(int i=0;str[i]!='\0';i++)
        {
           ly=str[i]-'a';
           cnt[ly]++;
           if(cnt[ly]>k)
           {
              while(str[st]!=str[i])
              {
                 cnt[str[st]-'a']--;
                 st++;
              }
               cnt[ly]--;
               st++;
           }
           ans+=i-st+1;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
时间: 2024-10-06 01:24:40

BestCoder Round #11 (Div. 2) 前三题题解的相关文章

BestCoder Round #11 (Div. 2)题解集合

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155    Accepted Submission(s): 110 Problem Description Bob and Alice got separated in the Square, they agreed that if they get sepa

BestCoder Round #11 (Div. 2) 题解

HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 302    Accepted Submission(s): 229 Problem Description Bob and Alice got separated in the Square, they agreed that if they

Codeforces Round #530 (Div. 2) (前三题题解)

总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高度的模拟,如果遇到石头就去判断一下会不会小于0其他没有什么好说的了 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int

HDU 5056 Boring count(BestCoder Round #11 (Div. 2))

Problem Description: You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K. Input: In the first line there is an integer

BestCoder Round #11 (Div. 2)

太菜,只能去Div2.(都做不完 ORZ... 分别是 HDU: 5054Alice and Bob 5055Bob and math problem 5056Boring count 5057Argestes and Sequence # 1001 碰面只能在坐标中间. 所以判断一下就好了. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<alg

DP BestCoder Round #50 (div.2) 1003 The mook jong

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的

(BestCoder Round #64 (div.2))Array -- BestCoder Round #64 (div.2)

BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在数列尾,并在两个数列间用0隔开.Vicky想做些改变,于是他将当天新产生的所有数字(包括0)全加1.Vicky现在想考考你,经过100天后,这个数列的前M项和是多少?. 输入描述 输入有多组数据. 第一行包含一个整数T,表示数据组数.T. \left( 1 \leq T \leq 2 * {10}^

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************

HDU 5651 xiaoxin juju needs help(BestCoder Round #77 (div.1)1001)

传送门 xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 861    Accepted Submission(s): 243 Problem Description As we all known, xiaoxin is a brilliant coder. He knew **palin