zn的手環
鏈接:https://ac.nowcoder.com/acm/contest/12180/A
來源:牛客網
題目描述
有人送了zn一個手環, 這個手環有檢測睡眠時長的功能,
為了檢測自己的手環是否能準確的測出自己的睡眠時長, zn在睡覺的時候特地記錄了入睡時間(可以看做zn一躺就睡
然后起床的時候記錄了起床時間
然后看了一眼自己的手環上顯示的睡眠時長
他想知道自己的手環對不對, 如果手環錯了那么真正的睡眠時長是多少呢
輸入描述:
前兩行按照"hour:minute p/a.m"的格式給出入睡時間和起床時間
第三行按照…h…min的形式給出手環上顯示的睡眠時長
輸出描述:
如果手環上的時長正確, 輸出單行"YES"(不帶引號
否則輸出兩行, 第一行為一個字串"NO"(不帶引號
接下來一行按照…h…min的形式給出真正的睡眠時長
示例1
輸入
復制
9:35 p.m
5:05 a.m
7h30min
輸出
復制
YES
備注:
有30%30%的資料滿足, 睡覺時間和起床時間同為早上下午
有40%40%的資料滿足, 睡覺時間永遠在下午
100%100%的資料滿足, 睡眠時長不超過24h
p.m或a.m與時間之間有一個空格的距離
模擬題函式的封裝是重要的
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 2e5 + 10;
const int M = N * N;
const long long mod = 998244353;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
int calc(string str, int l, int r){
int res = 0;
for (int i = l; i <= r; i ++){
res = res * 10 + (str[i] - '0');
}
return res;
}
void to_str(int x){
//string str = "";
int temp1 = x / 60;
int temp2 = x % 60;
cout << temp1;
cout << "h";
cout << temp2;
cout << "min" << endl;
}
signed main(){
string str1, str2;
getline(cin, str1);
getline(cin, str2);
int ans1 = 0, ans2 = 0;
int j;
for (int i = 0; i < str1.size(); i ++){
if (str1[i] == ':') ans1 += calc(str1, 0, i - 1) * 60 , j = i;
if (str1[i] == ' ') ans1 += calc(str1, j + 1, i - 1);
}
for (int i = 0; i < str2.size(); i ++){
if (str2[i] == ':') ans2 += calc(str2, 0, i - 1) * 60 , j = i;
if (str2[i] == ' ') ans2 += calc(str2, j + 1, i - 1);
}
string str3;
cin >> str3;
j = 0;
int ans3 = 0;
while(str3[j] != 'h'){
ans3 = ans3 * 10 + (str3[j] - '0');
j ++;
}
ans3 = ans3 * 60;
j ++;
if (str3[j + 1] == 'm') ans3 += calc(str3, j, j);
else ans3 += calc(str3, j, j + 1);
//cout << ans1 << " " << ans2 << " " << ans3 << endl;
char c1, c2;
for (int i = 0; i < str1.size(); i ++){
if (str1[i] == 'p') c1 = 'p';
if (str1[i] == 'a') c1 = 'a';
}
for (int i = 0; i < str2.size(); i ++){
if (str2[i] == 'p') c2 = 'p';
if (str2[i] == 'a') c2 = 'a';
}
if (c1 != c2){
ans2 += 12 * 60;
}
else if (ans2 <= ans1){
ans2 += 24 * 60;
}
if (ans2 - ans1 == ans3){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
to_str(ans2 - ans1);
}
return 0;
}
zn的游戲
鏈接:https://ac.nowcoder.com/acm/contest/12180/B
來源:牛客網
題目描述
某個課間, 同學們都在認真學習, 就zn在頹廢
zn在頹廢什么呢, 他在紙上隨便寫了n個數字, 然后他想找一個區間[l, r]使得這個區間包含全部數字的最大值和最小值, 并且這個區間長度盡可能小
輸入描述:
第一行一個整數n
第二行n個整數ai
輸出描述:
最小的區間長度
示例1
輸入
復制
4
2 3 2 3
輸出
復制
2
說明
任意一個大小為2的區間都能覆寫
備注:
20%20%的資料滿足, n\leq 100n≤100
50%50%的資料滿足, n\leq 10^3n≤10
3
80%80%的資料滿足, n\leq 10^6;n≤10
6
;
100%100%的資料滿足, n\leq 10^7; 0 \leq ai\leq 2 ^{31} - 1n≤10
7
;0≤ai≤2
31
?1
把所有位置存下來然后雙指標掃描即可
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 1e7 + 10;
const int M = N * N;
const long long mod = 998244353;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
vector<int> v1, v2;
int a[N];
signed main(){
int n;
gt(n);
int maxd = 0, mind = inf;
for (int i = 1; i <= n; i ++){
gt(a[i]);
maxd = max(maxd, a[i]);
mind = min(mind, a[i]);
}
for (int i = 1; i <= n; i ++){
if (a[i] == maxd) v1.push_back(i);
if (a[i] == mind) v2.push_back(i);
}
int ans = inf;
int j = 0;
for (int i = 0; i < v1.size(); i ++){
if (j < v2.size()) ans = min(ans, abs(v1[i] - v2[j]) + 1);
while(v2[j] < v1[i] && j < v2.size()){
ans = min(ans, abs(v1[i] - v2[j]) + 1);
j ++;
}
if (j < v2.size()) ans = min(ans, abs(v1[i] - v2[j]) + 1);
// if (ans == 2) break;
}
print(ans);
return 0;
}
zn的繩子
鏈接:https://ac.nowcoder.com/acm/contest/12180/C
來源:牛客網
題目描述
退役后的zn十分無助, 沒有人一起學文化課, 文化課還掉線, 掉線期間他玩起了繩子
有一個2 * n的平面, 然后有兩根很長的繩子, 第一根從左到右依次經過n個點, 第二根繩子從左到右依次經過另外n個點, 然后我們可以發現繩子之間有交叉點,
你想知道有多少種纏繩子的方案, 使得交叉點的數目 <= k
兩根繩子視為一模一樣的
由于答案過大, 請對10^9+710
9
+7取模輸出
輸入描述:
一行兩個整數n和k
輸出描述:
一個整數ans表示有多少種方案使得繩子交叉數目<=k
示例1
輸入
復制
2 1
輸出
復制
2
說明
第一種情況(1, 1) (2, 2)
第二種情況(1, 2) (2, 1)
共兩種情況
備注:
30%30%的資料滿足 n \leq 10n≤10
70%70%的資料滿足 n \leq 10^3n≤10
3
100%100%的資料滿足 n \leq 10^7;\ k \leq nn≤10
7
; k≤n
兩根繩子那樣依次連著,一個有n-1個空隙,里面要有k個交點所以,發現交點與交點之間是沒有聯系的,是任意的,所以我們可以從n-1個空西】格選擇0-k個,用組合數即可,但是資料范圍比較大,如何求逆元,可以倒著來求,n-1的階乘的逆元除以n就是n的階乘的逆元,所以n的階乘的逆元*n就是n-1的階乘的逆元,這樣倒著來即可
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 1e7 + 10;
const int M = N * N;
const int mod = 1e9 + 7;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
int fact[N], infact[N];
int n, k;
int qmi(int a, int b){
int res = 1;
while(b){
if (b & 1) res = res % mod * a % mod;
a = a % mod * a % mod;
b >>= 1;
}
return res;
}
void init(){
fact[0] = 1;
// infact[0] = 1;
for (int i = 1; i <= n; i++){
// cout << "---" << endl;
fact[i] = fact[i - 1] % mod * i % mod;
fact[i] %= mod;
}
infact[n] = qmi(fact[n], mod - 2);
for (int i = n - 1; i >= 0; i --){
infact[i] = infact[i + 1] % mod * (i + 1) % mod;
infact[i] %= mod;
}
}
int C(int a, int b){
return fact[a] % mod * infact[a - b] % mod * infact[b] % mod;
}
signed main(){
gt(n), gt(k);
n --;
init();
// cout << "---" << endl;
int ans = 0;
for (int i = 0; i <= min(n, k); i ++){
ans = ans % mod + C(n, i) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/259020.html
標籤:其他
