牛客OI周赛13-普及组

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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include  

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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include  

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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include  

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

你可能感兴趣的:(补题)