Alice and Bob
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 140 Accepted Submission(s): 99
Total Submission(s): 140 Accepted Submission(s): 99
题目链接:传送门
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).
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)
意解:水题
AC代码:
意解:水题
AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,m,x,y;
while(cin>>n>>m>>x>>y)
{
if(n - x == x && m - y == y) puts("YES");
else puts("NO");
}
return 0;
}
Bob and math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 375 Accepted Submission(s): 142
Total Submission(s): 375 Accepted Submission(s): 142
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:
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".
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)$.
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
意解:贪心处理,注意前导零;
AC代码:
意解:贪心,运用字符串的子串的前缀和技巧,和维护当前字母如果当前的字母不符合条件,则一一减去;
AC代码:
AC代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n,v,p,zoro,a[110];
while(cin>>n)
{
v = 10,p = zoro = 0;
for(int i = 0; i < n; i++)
{
scanf("%d", a + i);
if(a[i] % 2 && a[i] < v)
v = a[i], p = 1;
if(a[i] == 0) zoro++;
}
if(!p || zoro == n - 1 && zoro) puts("-1");
else
{
sort(a,a + n,cmp);
for(int i = 0; i < n; i++)
{
if(a[i] != v) printf("%d",a[i]);
else p = v,v = -1;
}
printf("%d\n",p);
}
}
return 0;
}
Boring count
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 194 Accepted Submission(s): 78
Total Submission(s): 194 Accepted Submission(s): 78
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
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
意解:贪心,运用字符串的子串的前缀和技巧,和维护当前字母如果当前的字母不符合条件,则一一减去;
AC代码:
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
typedef long long ll;
const int M = 1e5 + 100;
vector<int>dp[30];
char s[M];
int k;
void solve()
{
int p = -1;
ll ans = 0;
for(int i = 0; i < 26; i++) dp[i].clear();
scanf("%s %d",s,&k);
for(int i = 0; s[i]; i++)
{
int u = (int)(s[i] - 'a');
dp[u].push_back(i);
if(dp[u].size() > k)
{
p = max(p,dp[u][dp[u].size() - k - 1]);
}
ans += (i - p);
}
printf("%I64d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
solve();
}
return 0;
}