cf 1037(Div.3) AB
A
A. Only One Digit
time limit per test1 second
memory limit per test256 megabytes
You are given an integer 𝑥. You need to find the smallest non-negative integer 𝑦 such that the numbers 𝑥 and 𝑦 share at least one common digit. In other words, there must exist a decimal digit 𝑑 that appears in both the representation of the number 𝑥 and the number 𝑦.
Input
The first line contains an integer 𝑡 (1≤𝑡≤1000) — the number of test cases.
The first line of each test case contains one integer 𝑥 (1≤𝑥≤1000).
Output
For each test case, output one integer 𝑦 — the minimum non-negative number that satisfies the condition.
找这个数里最小的打印
点击查看代码
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
string s;
cin >> s;
char min = s[0];
for(char ch : s){
if(ch < min){
min = ch;
}
}
printf("%c\n", min);
}
return 0;
}
B
B. No Casino in the Mountains
time limit per test1 second
memory limit per test256 megabytes
You are given an array 𝑎 of 𝑛 numbers and a number 𝑘. The value 𝑎𝑖 describes the weather on the 𝑖-th day: if it rains on the 𝑖-th day, then 𝑎𝑖=1; otherwise, if the weather is good on the 𝑖-th day, then 𝑎𝑖=0.
Jean wants to visit as many peaks as possible. One hike to a peak takes exactly 𝑘 days, and during each of these days, the weather must be good (𝑎𝑖=0). That is, formally, he can start a hike on day 𝑖 only if all 𝑎𝑗=0 for all 𝑗 (𝑖≤𝑗≤𝑖+𝑘−1).
After each hike, before starting the next one, Jean must take a break of at least one day, meaning that on the day following a hike, he cannot go on another hike.
Find the maximum number of peaks that Jean can visit.
Input
Each test consists of several test cases. The first line contains a single integer 𝑡 (1≤𝑡≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers 𝑛 and 𝑘 (1≤𝑛≤105, 1≤𝑘≤𝑛).
The second line contains 𝑛 numbers 𝑎𝑖 (𝑎𝑖∈{0,1}), where 𝑎𝑖 denotes the weather on the 𝑖-th day.
It is guaranteed that the total value of 𝑛 across all test cases does not exceed 105.
Output
For each test case, output a single integer: the maximum number of hikes that Jean can make.
0表示好天气,1表示坏天气,好天气才能出行,连续k天才能走完一段行程,每走完一段都需要休息一天,问最大能走几段。
点击查看代码
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int a[100005];
for(int i = 0; i < n; i++){
cin >> a[i];
}
int cnt = 0;
int hill = 0;
for(int i = 0; i < n; i++){
if(a[i] == 0){
cnt++;
if(cnt == k){
hill++;
cnt = 0;
i++;
}
}else{
cnt = 0;
}
}
printf("%d\n", hill);
}
return 0;
}

浙公网安备 33010602011771号