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 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
 

/**
* Created by ckboss on 14-10-3.
*/
import java.util.*; public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int N=in.nextInt();
int M=in.nextInt();
int x=in.nextInt();
int y=in.nextInt();
if(x==N-x&&y==M-y)
System.out.println("YES");
else
System.out.println("NO");
}
}
}

HDOJ5055 Bob and math problem

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

Total Submission(s): 812    Accepted Submission(s): 313

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 which indicate the digit $a_1, a_2, a_3, \cdots, a_n. ( 0 \leq 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
 

/**
* Created by ckboss on 14-10-3.
*/
import java.util.*; public class Main { static int[] num = new int[10];
static char[] ans = new char[110];
static int nt;
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n;
while(in.hasNext()){
n=in.nextInt();
int flag=0;
int MinJ=111;
Arrays.fill(num,0); nt=0;
for(int i=0;i<n;i++){
int x=in.nextInt();
num[x]++;
if(x%2==1){
if(x<MinJ) MinJ=x;
flag++;
}
}
if(flag==0)
{
System.out.println("-1");
continue;
}
num[MinJ]--;
for(int i=9;i>=0;i--){
for(int j=num[i];j>0;j--){
ans[nt++]=(char)('0'+i);
}
}
ans[nt++]=(char)(MinJ+'0');
flag=0;
for(int i=0;i<nt;i++){
if(ans[i]=='0' && flag==0){
flag=0; break;
}
flag=1;
System.out.print(ans[i]);
}
if(flag==1)
System.out.println("");
else
System.out.println("-1");
}
}
}

HDOJ5056 Boring count

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

Total Submission(s): 615    Accepted Submission(s): 242

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
 

O(n)贪心...

/**
* Created by ckboss on 14-10-3.
*/
import java.util.*; public class Main { static long[] num = new long[30]; public static void main(String[] args){
Scanner in = new Scanner(System.in);
int T_T=in.nextInt();
while(T_T-->0){
String st=in.next();
int k=in.nextInt();
Arrays.fill(num,0);
int be=0,ed=0;
long ans=0;
for(int i=0,sz=st.length();i<sz;i++){
int id=(int)(st.charAt(i)-'a');
num[id]++;
if(num[id]>k){
for(;be<=ed;be++){
ans+=ed-be+1;
num[st.charAt(be)-'a']--;
if(st.charAt(be)-'a'==id) {
be++;
break;
}
}
}
ed=i;
}
for(;be<=ed;be++){
ans+=ed-be+1;
num[st.charAt(be)-'a']--;
}
System.out.println(ans);
}
}
}

HDOJ5057 Argestes and Sequence

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 603    Accepted Submission(s): 152

Problem Description
Argestes has a lot of hobbies and likes solving query problems especially. One day Argestes came up with such a problem. You are given a sequence a consisting of N nonnegative integers, a[1],a[2],...,a[n].Then there are M operation on the sequence.An operation
can be one of the following:

S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).

Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.

Note: The 1st digit of a number is the least significant digit.
 
Input
In the first line there is an integer T , indicates the number of test cases.

For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],...,a[n]—initial value of array elements.

Each of the next M lines begins with a character type.

If type==S,there will be two integers more in the line: X,Y.

If type==Q,there will be four integers more in the line: L R D P.



[Technical Specification]

1<=T<= 50

1<=N, M<=100000

0<=a[i]<=$2^{31}$ - 1

1<=X<=N

0<=Y<=$2^{31}$ - 1

1<=L<=R<=N

1<=D<=10

0<=P<=9
 
Output
For each operation Q, output a line contains the answer.
 
Sample Input
1
5 7
10 11 12 13 14
Q 1 5 2 1
Q 1 5 1 0
Q 1 5 1 1
Q 1 5 3 0
Q 1 5 3 1
S 1 100
Q 1 5 3 1
 
Sample Output
5
1
1
5
0
1
 
Source
 

分块大法好....

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const int maxn=100100; struct BLOCK
{
int cnt[10][10];
}block[400];
int block_size,block_num;
int n,m;
int a[maxn]; const int ten[12]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; void CHANGE(int p,int v)
{
int id=p/block_size;
int x=a[p];
for(int i=0;i<10;i++)
{
block[id].cnt[i][x%10]--;
x/=10;
}
a[p]=v;
x=v;
for(int i=0;i<10;i++)
{
block[id].cnt[i][x%10]++;
x/=10;
}
} int QUERY(int l,int r,int p,int d)
{
int L=l/block_size,R=r/block_size;
int ans=0;
if(R-L<=1)
{
for(int i=l;i<=r;i++)
{
ans+=((a[i]/ten[p-1])%10==d)?1:0;
}
return ans;
}
for(int i=l;i<(L+1)*block_size;i++)
{
ans+=((a[i]/ten[p-1])%10==d)?1:0;
}
for(int i=L+1;i<=R-1;i++)
{
ans+=block[i].cnt[p-1][d];
}
for(int i=R*block_size;i<=r;i++)
{
ans+=((a[i]/ten[p-1])%10==d)?1:0;
}
return ans;
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d%d",&n,&m);
memset(block,0,sizeof(block));
block_size=sqrt(n*1.0)+1;
block_num=n/block_size+1;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int x=a[i];
int id=i/block_size;
for(int j=0;j<10;j++)
{
block[id].cnt[j][x%10]++;
x/=10;
}
}
while(m--)
{
char op[10];
int a,b,c,d;
scanf("%s",op);
if(op[0]=='Q')
{
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("%d\n",QUERY(a,b,c,d));
}
else if(op[0]=='S')
{
scanf("%d%d",&a,&b);
CHANGE(a,b);
}
}
}
return 0;
}

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

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

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  2. BestCoder Round #11 (Div. 2)

    太菜,仅仅能去Div2.(都做不完 ORZ... 各自是 HDU: 5054pid=5054"> Alice and Bob 5055Bob and math problem 5056 ...

  3. 喵哈哈村的魔法考试 Round #11 (Div.2) 题解

    喵哈哈村的星星与月亮(一) 打表发现答案就等于a*b%mod 注意a*b可能爆longlong #include<bits/stdc++.h> using namespace std; c ...

  4. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  5. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  6. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  7. hdu5631 BestCoder Round #73 (div.2)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  8. hdu5630 BestCoder Round #73 (div.2)

    Rikka with Chess  Accepts: 393  Submissions: 548  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

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

    BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...

随机推荐

  1. Oracle批量执行脚本文件

    以下是Oracle批量执行脚本文件的步骤和方法 1.创建脚本文件(xx.sql): 例如文件CreateTable Create table tb1( id varchar2(30), Name va ...

  2. java.lang.VerifyError

    public class VerifyErrorextends LinkageError Thrown when the "verifier" detects that a cla ...

  3. What is Observer and Observable and when we used these?

    转会:http://stackoverflow.com/questions/13744450/interview-when-do-we-use-observer-and-observable

  4. iOS kvc

    kvc在我的脑海里用来更改属性的实例变量值. 今天,他们遇到了kvc第二次去学习它,在网上看了很多博客,这似乎不符合我的口味,为了提取一些以下的.总结自己的. http://www.cnblogs.c ...

  5. 如何有效抓取SQL Server的BLOCKING信息

    原文:如何有效抓取SQL Server的BLOCKING信息 转自:微软亚太区数据库技术支持组 官方博客 http://blogs.msdn.com/b/apgcdsd/archive/2011/12 ...

  6. Android MenuItem 设置文本颜色-TextColor设置

    前面一直在寻找 MenuItem文字颜色设置. 我发现API唯一的背景颜色设置. .. 因此,找到下面的方法.在OverFlow看到. 在onCreateOptionsMenu一下. 使MenuIte ...

  7. Java的结构之美【1】——构造对象

    当我们遇到多个构造器參数的时候可能会想到用构件器,代码例如以下: /** * 构建器 * @author 阳光小强 * */ public class Lunch { private String c ...

  8. Qt原始资源形象问题后删除

        这些天Qt请项目超市收银系统,作为练一练手,无论如何,亦休闲亦无关,做几乎同样的.旨在取代以前的资源图片, 是什么改变了,码里面的路径都改了.还是编译只是去,总是提示这样一个错误. <s ...

  9. Java在的时候,类定义HashSet初始化方法

    Java非常多的时间,应使用HashSet搜索功能,类的则定义,是HashSet类型的,我们定义数据成员之后,不好直接调用add函数来实现初始化,这个时候怎么办? 我们能够这样来做: public s ...

  10. IIS7安装场景对照表

    原文 IIS7安装场景对照表 Default Server Install Components Server Manager Update Name Static Content IIS-Stati ...