目录
一、试试手气
我们知道一个骰子有 6 个面,分别刻了 1 到 6 个点。下面给你 6 个骰子的初始状态,即它们朝上一面的点数,让你一把抓起摇出另一套结果。假设你摇骰子的手段特别精妙,每次摇出的结果都满足以下两个条件:
- 1、每个骰子摇出的点数都跟它之前任何一次出现的点数不同;
- 2、在满足条件 1 的前提下,每次都能让每个骰子得到可能得到的最大点数。
那么你应该可以预知自己第 n 次(1≤n≤5)摇出的结果。
输入格式:
输入第一行给出 6 个骰子的初始点数,即 [1,6] 之间的整数,数字间以空格分隔;第二行给出摇的次数 n(1≤n≤5)。
输出格式:
在一行中顺序列出第 n 次摇出的每个骰子的点数。数字间必须以 1 个空格分隔,行首位不得有多余空格。
输入样例:
3 6 5 4 1 4
3
输出样例:
4 3 3 3 4 3
样例解释:
这 3 次摇出的结果依次为:
6 5 6 6 6 6
5 4 4 5 5 5
4 3 3 3 4 3
最终代码:
void L7_6(){
vector<int>ar(6);
vector<int>br(6);
vector<bool>ind(6,false);
for(int i=0;i<6;i++){
cin>>ar[i];
br[i]=ar[i];
if(ar[i]==6)
ind[i]=true;
}
int n;
cin>>n;
for(int k = 0;k<n;k++){
for(int i =0;i<6;i++){
if(ind[i]==false){
ar[i]=6;
ind[i]=true;
}
else if(ind[i]==true){
ar[i]--;
if(ar[i]==br[i])
ar[i]--;
}
}
}
for(int j=0;j<6;j++){
if(j==0)
cout<<ar[j];
else
cout<<" "<<ar[j];
}
}
int main(){
L7_6();
return 0;
}
二、机工士姆斯塔迪奥
在 MMORPG《最终幻想14》的副本“乐欲之所瓯博讷修道院”里,BOSS 机工士姆斯塔迪奥将会接受玩家的挑战。
你需要处理这个副本其中的一个机制:N×M 大小的地图被拆分为了 N×M 个 1×1 的格子,BOSS 会选择若干行或/及若干列释放技能,玩家不能站在释放技能的方格上,否则就会被击中而失败。
给定 BOSS 所有释放技能的行或列信息,请你计算出最后有多少个格子是安全的。
输入格式:
输入第一行是三个整数 N,M,Q (1≤N×M≤105,0≤Q≤1000),表示地图为 N 行 M 列大小以及选择的行/列数量。
接下来 Q 行,每行两个数 Ti,Ci,其中 Ti=0 表示 BOSS 选择的是一整行,Ti=1 表示选择的是一整列,Ci 为选择的行号/列号。行和列的编号均从 1 开始。
输出格式:
输出一个数,表示安全格子的数量。
输入样例:
5 5 3
0 2
0 4
1 3
输出样例:
12
最终代码:
void L7_8(){
int N, M, Q;
cin >> N >> M >> Q;
unordered_set<int> rows;
unordered_set<int> cover;
for (int i = 0; i < Q; ++i) {
int T, C;
cin >> T >> C;
if (T == 0) {
rows.insert(C);
} else {
cover.insert(C);
}
}
int total_cells = N * M;
int safe_cells = total_cells - (rows.size() * M + cover.size() * N - rows.size() * cover.size());
cout << safe_cells << endl;
}
int main(){
L7_8();
return 0;
}
三、老板的作息表
新浪微博上有人发了某老板的作息时间表,表示其每天 4:30 就起床了。但立刻有眼尖的网友问:这时间表不完整啊,早上九点到下午一点干啥了?
本题就请你编写程序,检查任意一张时间表,找出其中没写出来的时间段。
输入格式:
输入第一行给出一个正整数 N,为作息表上列出的时间段的个数。随后 N 行,每行给出一个时间段,格式为:
hh:mm:ss - hh:mm:ss
其中 hh
、mm
、ss
分别是两位数表示的小时、分钟、秒。第一个时间是开始时间,第二个是结束时间。题目保证所有时间都在一天之内(即从 00:00:00 到 23:59:59);每个区间间隔至少 1 秒;并且任意两个给出的时间区间最多只在一个端点有重合,没有区间重叠的情况。
输出格式:
按照时间顺序列出时间表中没有出现的区间,每个区间占一行,格式与输入相同。题目保证至少存在一个区间需要输出。
输入样例:
8
13:00:00 - 18:00:00
00:00:00 - 01:00:05
08:00:00 - 09:00:00
07:10:59 - 08:00:00
01:00:05 - 04:30:00
06:30:00 - 07:10:58
05:30:00 - 06:30:00
18:00:00 - 19:00:00
输出样例:
04:30:00 - 05:30:00
07:10:58 - 07:10:59
09:00:00 - 13:00:00
19:00:00 - 23:59:59
最终代码:
#include<bits/stdc++.h>
using namespace std;
void L7_1(){
cout<<"I'm gonna win! Today!"<<endl<<"2022-04-23"<<endl;
}
void L7_2(){
int n,a;
cin>>n>>a;
cout<<n/a<<endl;
}
void L7_3(){
int a, b, c, d;
cin >> a >> b >> c >> d;
if (c >= a && d >= a) {
cout << c << "-Y " << d << "-Y" << endl;
cout << "huan ying ru guan" << endl;
} else if (c >= a && d < a) {
if (c >= b) {
cout << c << "-Y " << d << "-Y" << endl;
cout << "qing 1 zhao gu hao 2" << endl;
} else {
cout << c << "-Y " << d << "-N" << endl;
cout << "1: huan ying ru guan" << endl;
}
} else if (d >= a && c < a) {
if (d >= b) {
cout << c << "-Y " << d << "-Y" << endl;
cout << "qing 2 zhao gu hao 1" << endl;
} else {
cout << c << "-N " << d << "-Y" << endl;
cout << "2: huan ying ru guan" << endl;
}
} else {
cout << c << "-N " << d << "-N" << endl;
cout << "zhang da zai lai ba" << endl;
}
}
int cal(int n){
int result = 1;
for (int i = 1; i <= n; ++i) {
result *= i;
}
return result;
}
void L7_4()
{
int A, B;
cin >> A >> B;
int sum = A + B;
int result = cal(sum);
cout << result << endl;
}
void L7_6(){
vector<int>ar(6);
vector<int>br(6);
vector<bool>ind(6,false);
for(int i=0;i<6;i++){
cin>>ar[i];
br[i]=ar[i];
if(ar[i]==6)
ind[i]=true;
}
int n;
cin>>n;
for(int k = 0;k<n;k++){
for(int i =0;i<6;i++){
if(ind[i]==false){
ar[i]=6;
ind[i]=true;
}
else if(ind[i]==true){
ar[i]--;
if(ar[i]==br[i])
ar[i]--;
}
}
}
for(int j=0;j<6;j++){
if(j==0)
cout<<ar[j];
else
cout<<" "<<ar[j];
}
}
struct Student {
int tts;
int pta;
bool flag;
};
bool cmp(const Student &a, const Student &b) {
if (a.tts == b.tts) {
return a.pta < b.pta;
}
return a.tts < b.tts;
}
void L7_7(){
int N, K, S;
cin >> N >> K >> S;
int a;
int b;
vector<Student> students(N);
for (int i = 0; i < N; ++i) {
cin>>a;
if(a>=175)
{
cin>>students[i].pta;
students[i].tts =a;
students[i].flag=false;
}else{
cin>>b;
i--;
N--;
}
}
sort(students.begin(), students.begin()+N, cmp);
int Count = 0;
int lasttts = -1;
for(int pc=0;pc<K;pc++){
lasttts=-1;
for (int i=0;i<students.size();i++) {
if (students[i].flag==false&&(students[i].tts > lasttts ||
(students[i].tts == lasttts && students[i].pta >= S))) {
Count++;
lasttts = students[i].tts;
students[i].flag = true;
}
}
}
cout << Count << endl;
}
void L7_8(){
int N, M, Q;
cin >> N >> M >> Q;
unordered_set<int> rows;
unordered_set<int> cover;
for (int i = 0; i < Q; ++i) {
int T, C;
cin >> T >> C;
if (T == 0) {
rows.insert(C);
} else {
cover.insert(C);
}
}
int total_cells = N * M;
int safe_cells = total_cells - (rows.size() * M + cover.size() * N - rows.size() * cover.size());
cout << safe_cells << endl;
}
void bran(int N, int M, int K, vector<int>& needles) {
stack<int> box;
queue<int> conveyor(deque<int>(needles.begin(), needles.end()));
vector<int> current_branch;
while (!conveyor.empty()) {
int needle = conveyor.front();
conveyor.pop();
if (current_branch.empty() || needle <= current_branch.back()) {
current_branch.push_back(needle);
} else {
while (!box.empty() && box.top() > current_branch.back()) {
conveyor.push(box.top());
box.pop();
}
if (!box.empty() && box.top() <= current_branch.back()) {
current_branch.push_back(box.top());
box.pop();
} else {
if (box.size() < M) {
box.push(needle);
} else {
for (int n : current_branch) {
cout << n << " ";
}
cout << endl;
current_branch.clear();
conveyor.push(needle);
}
}
}
if (current_branch.size() == K) {
for (int n : current_branch) {
cout << n << " ";
}
cout << endl;
current_branch.clear();
}
}
while (!current_branch.empty()) {
for (int n : current_branch) {
cout << n << " ";
}
cout << endl;
current_branch.clear();
}
}
void L7_9(){
int N, M, K;
cin >> N >> M >> K;
vector<int> needles(N);
for (int i = 0; i < N; ++i) {
cin >> needles[i];
}
bran(N, M, K, needles);
}
//
//bool compareTime(const pair<string, string>& a, const pair<string, string>& b) {
// return a.first < b.first;
//}
//
//
//int timeDiff(const string& start, const string& end) {
// int startHour, startMinute, startSecond;
// int endHour, endMinute, endSecond;
//
// istringstream startStream(start);
// istringstream endStream(end);
//
// char colon;
//
// startStream >> startHour >> colon >> startMinute >> colon >> startSecond;
// endStream >> endHour >> colon >> endMinute >> colon >> endSecond;
//
// int startTotalSeconds = startHour * 3600 + startMinute * 60 + startSecond;
// int endTotalSeconds = endHour * 3600 + endMinute * 60 + endSecond;
//
// // 计算时间差
// int diffSeconds = endTotalSeconds - startTotalSeconds;
//
// // 处理跨天情况
// if (diffSeconds < 0) {
// diffSeconds += 24 * 3600; // 加一天的秒数
// }
//
// return diffSeconds;
//}
void L7_10(){
int n;
cin >> n;
getchar();
set<string> res;
while (n--)
{
string str;
getline(cin, str);
res.insert(str);
}
auto head = res.begin();
if ((*head).substr(0, 8) != "00:00:00")
{
cout << "00:00:00" << " - " << (*head).substr(0, 8) << endl;
}
for (auto p = res.begin(); p != (--res.end()); p++)
{
auto q = p;
string s1 = (*q).substr(11, 8);
q++;
string s2 = (*q).substr(0, 8);
if (s1 != s2)
{
cout << s1 << " - " << s2 << endl;
}
}
auto rear = (--res.end());
if ((*rear).substr(11, 8) != "23:59:59")
{
cout << (*rear).substr(11, 8) << " - " << "23:59:59" << endl;
}
}
int main(){
L7_10();
return 0;
}