第三场天梯赛
过题数:11/15
得分:175/290
L1-1 今天我要赢
输出题:
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
cout<<"I'm gonna win! Today!"<<endl;
cout<<"2022-04-23"<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-2 种钻石
同样的签到题,直接输出商就好,天梯赛不记罚时,可以不用因为有坑而提心吊胆。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
int n,v;
cin>>n>>v;
cout<<n/v<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-3 谁能进图书馆
这个就按照题目意思模拟就好,按两个人的年龄关系,分各种情况讨论。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
int jin,pei,x1,x2;
cin>>jin>>pei>>x1>>x2;
if(max(x1,x2)>=pei or min(x1,x2)>=jin){
cout<<x1<<"-Y"<<" "<<x2<<"-Y"<<endl;
if(x1>=jin and x2>=jin){
cout<<"huan ying ru guan"<<endl;
}else if(x1>=pei){
cout<<"qing 1 zhao gu hao 2"<<endl;
}else if(x2>=pei){
cout<<"qing 2 zhao gu hao 1"<<endl;
}
return;
}if(max(x1,x2)<jin){
cout<<x1<<"-N"<<" "<<x2<<"-N"<<endl;
cout<<"zhang da zai lai ba"<<endl;
return;
}if(max(x1,x2)>=jin and min(x1,x2)<jin){
if(x1>=jin and x2<jin){
cout<<x1<<"-Y"<<" "<<x2<<"-N"<<endl;
cout<<1<<": huan ying ru guan"<<endl;
}else if(x2>=jin and x1<jin){
cout<<x1<<"-N"<<" "<<x2<<"-Y"<<endl;
cout<<2<<": huan ying ru guan"<<endl;
}
return;
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-4 拯救外星人
这个因为只有12的阶乘,不用担心超范围。我们直接输出(A+B)的阶乘就好了。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
int a,b;
cin>>a>>b;
int x=1;
int k=1;
while(k<=a+b){
x*=k;
k++;
}
cout<<x<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-5 试试手气
这个因为范围很小,我们可以直接进行模拟去尝试,记录每个骰子出现过的数字,然后每次出现的是没出现过的最大的。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
map<int,int>u[7];
int a[7];
for(int i=1;i<=6;i++){
cin>>a[i];
u[i][a[i]]++;
}
int x;
cin>>x;
while(x--){
for(int i=1;i<=6;i++){
int max1=0;
for(int j=1;j<=6;j++){
if(u[i][j]==0){
max1=j;
}
}
a[i]=max1;
u[i][max1]=1;
}
}
for(int i=1;i<=6;i++){
cout<<a[i];
if(i!=6){
cout<<" ";
}
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-6 斯德哥尔摩火车上的题
这个就是把题目上给的代码进行复制粘贴, 把那个代码生成的内容进行比较。如果连个字符串生成出来的内容一样我们就输出一行,否则输出两行。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
string a,b;
getline(cin,a);
getline(cin,b);
string s1,s2;
s1=s2="";
for(int i = 1; i <a.size(); i++) {
if((a[i]-'0') % 2 == (a[i-1]-'0') % 2) {
s1+= max(a[i], a[i-1]);
}
}
for(int i = 1; i <b.size(); i++) {
if((b[i]-'0') % 2 == (b[i-1]-'0') % 2) {
s2+= max(b[i], b[i-1]);
}
}
if(s1==s2){
cout<<s1<<endl;
}else{
cout<<s1<<endl<<s2<<endl;
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-7 机工士姆斯塔迪奥
这个我们记录释放技能的行和列。
然后进行遍历,如果行和列都没有受到攻击,我们++。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
int n,m,q;
cin>>n>>m>>q;
map<int,int>u,v;
for(int i=1;i<=q;i++){
int t,c;
cin>>t>>c;
if(t==0){
u[c]++;
}else{
v[c]++;
}
}
int sum=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(u[i]==0 and v[j]==0){
sum++;
}
}
}
cout<<sum<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L1-8 静静的推荐
题目中所描述的天梯赛成绩>=175,以及pta>=s(第一个例子里是90)的人是无论如何都可以接受的,所以一旦有人满足了这个条件,推荐的学生人数就加一,接下来我们要考虑的就是只有天梯赛成绩>=175的人。我们可以用一个下标为各个成绩的数组来进行判断,判断它是否有超过推荐批次。(在不考虑pta>=s的情况下,也就是pta<s时,每一批次,每一个分值的人都只能推荐一个,因为题目中描述的是严格递增)所以数值中的值就是它的批次,每当有人满足成绩>175时,批次就加一,直到超过题中给定的批次。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
struct stu{
int f;
int p;
int k;
int as;
};
int k1[300],k2[300];
void miaojiachun() {
int n,kk,s;
cin>>n>>kk>>s;
vector<stu>a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i].f>>a[i].p;
a[i].k=0;
a[i].as=i;
}
int sum=0;
for(int i=1;i<=n;i++){
if(a[i].f>=175){
if(a[i].p>=s){
k1[a[i].f]++;
}else{
k2[a[i].f]++;
}
}
}
for(int i=175;i<=290;i++){
sum+=k1[i];
sum+=min(k2[i],kk);
}
cout<<sum<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L2-1 插松枝
一个很兔妈那啥的大模拟,模拟死我了。
这个主要是利用multiset,因为这个数据结构可以自动按大到小排序,并且不会去重。我们可以用这个来模拟我们的手,由题意可以知道小盒子要用栈模拟,推进器要用队列模拟,有一个坑点是题面说当小盒子满了,并且推进器上的松枝不满足要求的时候,要压回推进器,这个是回到队头而不是插入队尾,所以我们当这个情况发生时,我们不对队列进行弹出操作。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
void miaojiachun() {
int n, m, k;
cin >> n >> m >> k;
queue<int> q;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
q.push(x);
}
stack<int> hz;
multiset<int> a;
while (!q.empty()) {
if (a.size() == k) {
// 输出
auto it = a.rbegin();
cout << *it;
++it;
for (; it != a.rend(); ++it) {
cout << " " << *it;
}
cout << endl;
a.clear();
}
if (hz.empty()) {
int x = q.front();
q.pop();
if (a.size() == 0 || (*a.begin() >= x && a.size() < k)) {
a.insert(x);
} else {
hz.push(x);
}
} else if (hz.size() < m) {
int x = hz.top();
if (x > *a.begin() && a.size() != 0) {
int y = q.front();
q.pop();
if (y <= *a.begin()) {
a.insert(y);
} else {
hz.push(y);
}
} else {
a.insert(x);
hz.pop();
}
} else if (hz.size() == m) {
int x = hz.top();
if (x > *a.begin() && a.size() != 0) {
int y = q.front();
if (y <= *a.begin()) {
a.insert(y);
q.pop();
} else {
// 输出
auto it = a.rbegin();
cout << *it;
++it;
for (; it != a.rend(); ++it) {
cout << " " << *it;
}
cout << endl;
a.clear();
}
} else {
a.insert(x);
hz.pop();
}
}
}
while (!hz.empty()) {
if (a.size() == k) {
// 输出
auto it = a.rbegin();
cout << *it;
++it;
for (; it != a.rend(); ++it) {
cout << " " << *it;
}
cout << endl;
a.clear();
}
int x = hz.top();
if (x > *a.begin() && a.size() != 0) {
// 输出
auto it = a.rbegin();
cout << *it;
++it;
for (; it != a.rend(); ++it) {
cout << " " << *it;
}
cout << endl;
a.clear();
} else {
a.insert(x);
hz.pop();
}
}
if (a.size() != 0) {
// 输出
auto it = a.rbegin();
cout << *it;
++it;
for (; it != a.rend(); ++it) {
cout << " " << *it;
}
cout << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L2-2 老板的作息表
也是一个模拟,因为时间段没有重叠,我们对时间段进行排序然后就直接找空隙进行输出就好了。
注意一天的开始和结束。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
struct kk{
string s1,s2;
};
bool cmp(kk a,kk b){
return a.s1<b.s1;
}
void miaojiachun() {
int n;
cin>>n;
vector<kk>s(n+1);
for(int i=1;i<=n;i++){
cin>>s[i].s1;
string adf;
cin>>adf;
cin>>s[i].s2;
// cout<<s[i].s1<<" "<<s[i].s2<<endl;
}
sort(s.begin()+1,s.end(),cmp);
vector<kk>ans;
if(n==1){
if(s[1].s1!="00:00:00"){
ans.push_back({"00:00:00",s[1].s1});
}
if(s[n].s2!="23:59:59"){
ans.push_back({s[n].s2,"23:59:59"});
}
for(int i=0;i<ans.size();i++){
cout<<ans[i].s1<<" - "<<ans[i].s2<<endl;
}
return;
}
for(int i=1;i<n;i++){
if(i==1){
if(s[i].s1!="00:00:00"){
ans.push_back({"00:00:00",s[i].s1});
}
}
if(s[i].s2!=s[i+1].s1){
ans.push_back({s[i].s2,s[i+1].s1});
}
}
if(s[n].s2!="23:59:59"){
ans.push_back({s[n].s2,"23:59:59"});
}
for(int i=0;i<ans.size();i++){
cout<<ans[i].s1<<" - "<<ans[i].s2<<endl;
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}
L2-3 龙龙送外卖
原理就是每增加一个点就往上找到走过的点,我们先距离*2, 记录还要回去,并记录当前深度,记住最大的深度减去,意思就是最长的路咱们最后走,走完不返回。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const int inf = LLONG_MAX / 10;
const int mod = 998244353;
#define x first
#define y second
int fa[N];
int g;
bool vis[N];
int ju[N];
int sum=0;
int max1=0;
int dfs(int x){
if(x==g or ju[x]!=0){
return ju[x];
}
ju[x]=dfs(fa[x])+1;
sum++;
return ju[x];
}
void miaojiachun() {
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>fa[i];
if(fa[i]==-1){
ju[i]=0;
g=i;
}
vis[i]=false;
}
while(m--){
int x;
cin>>x;
max1=max(dfs(x),max1);
cout<<sum*2-max1<<endl;
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int ING = 1;
// cin >> ING;
while (ING--) {
miaojiachun();
}
return 0;
}

浙公网安备 33010602011771号