本期封面原图 画师村カルキ
牛客周赛 Round 70 五题
A - 小苯晨跑
思路
没啥好说的
代码
//
// Created by Swan416 on 2024-12-01 18:57.
//
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void solve()
{int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);if(a==b and b==c and c==d)printf("NO\n");elseprintf("YES\n");
}int main()
{int T=1;scanf("%d",&T);while(T--){solve();}return 0;
}
B - 小苯过马路
思路
没啥好说的,题面有点歧义的,总之小苯遵守交规就意味着现在绿灯剩下的事件小于他过马路的时间他也不会走
代码
//
// Created by Swan416 on 2024-12-01 19:01.
//
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void solve()
{int x,y,k,t;char G;cin>>x>>y>>k>>t>>G;if(G=='G'){if(k>=t)printf("%d\n", t);elseprintf("%d\n",t+k+x);}else{printf("%d\n",t+k);}
}int main()
{int T=1;//scanf("%d",&T);while(T--){solve();}return 0;
}
C - 小苯的字符串染色
思路
不需要最小化操作次数,最多操作n次,1也是奇数,所以我们就把黑的一个一个改就行了
代码
//
// Created by Swan416 on 2024-12-01 19:05.
//
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void solve()
{int n;scanf("%d",&n);string s;cin>>s;int onw_cnt=0;for(int i=0;i<n;i++){if(s[i]=='1'){onw_cnt++;}}printf("%d\n",onw_cnt);for(int i=0;i<n;i++){if(s[i]=='1'){printf("%d %d\n",i+1,i+1);}}
}int main()
{int T=1;scanf("%d",&T);while(T--){solve();}return 0;
}
D - 小苯的能量项链
思路
遍历左边丢掉几个,那么右边最多丢掉几个也就知道了,在可能出现的所有最右端点里面取最大的,我用的线段树但是应该维护一个后缀最大值就够了
代码
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int tree[2000044],arr[500010],ans;
void build_tree(int node,int start,int ends)
{if(start==ends){tree[node]=arr[start];}else{int mid=(start+ends)/2;int left_node=2*node;int right_node=2*node+1;build_tree(left_node,start,mid);build_tree(right_node,mid+1,ends);tree[node]=max(tree[left_node],tree[right_node]);}
}
void query(int node,int start,int ends,int L,int R)
{if(L<=start&&R>=ends){ans=max(ans,tree[node]);//ans来记录最大值}else{int mid=(start+ends)/2;int left_node=2*node;int right_node=2*node+1;if(L<=mid){//查询区间又涉足到左子树的,就查询一下左儿子query(left_node,start,mid,L,R);}if(R>mid){//只有区间又涉足到右侧的,就需要查询一下右儿子query(right_node,mid+1,ends,L,R);}}
}void solve()
{int n,k;scanf("%d%d",&n,&k);for(int i=1;i<=n;i++){scanf("%d",&arr[i]);}
// if(n==1)
// {
// printf("%d\n",arr[1]);
// return;
// }
// else if(n==2)
// {
// printf("%d\n",arr[1]+arr[2]);
// return;
// }build_tree(1,1,n);//遍历左边删几个ll ret=0;for(int i=0;i<=min(n,k);i++){int right=k-i;ll cur=arr[i+1];ans=0;int l=max(i+2,n-right);if(l<=n)query(1,1,n,l,n);cur+=ans;ret=max(cur,ret);}printf("%lld\n",ret);
}int main()
{int T=1;scanf("%d",&T);while(T--){solve();}return 0;
}
E - 小苯的最短路
思路
用dijkstra写一个打表,打表代码
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N=100;
vector<pii> G[N];
int n;
bool bl[N];
ll dis[N];
void dijkstra()
{memset(bl,0,sizeof(bl));memset(dis,0x3f,sizeof(dis));priority_queue<pii,vector<pii>,greater<pii>> q;q.push({0,1});dis[1]=0;while(!q.empty()){
// printf("%d %d\n",q.top().first,q.top().second);//debugint u=q.top().second;q.pop();if(bl[u]){continue;}bl[u]=true;for(auto [v,w]:G[u]){if(dis[v]>dis[u]+w){dis[v]=dis[u]+w;q.push({dis[v],v});}}}
}void solve()
{printf("%d -> ",n);for(int i=1;i<=n;i++){G[i].clear();}
// printf("building graph:\n");for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(i!=j)G[i].push_back({j,i^j});
// printf("%d ",i^j);}
// printf("\n");}
// printf("dijkstra:\n");dijkstra();ll ans=0;for(int i=1;i<=n;i++){
// printf("%lld ",dis[i]);if(i==1)ans=dis[i];elseans^=dis[i];}printf("%lld\n",ans);
}int main()
{for(n=1;n<=99;n++){solve();}return 0;
}
输出的结果是
1 -> 0
2 -> 3
3 -> 1
4 -> 4
5 -> 0
6 -> 7
7 -> 1
8 -> 8
9 -> 0
10 -> 11
11 -> 1
12 -> 12
13 -> 0
14 -> 15
15 -> 1
16 -> 16
17 -> 0
18 -> 19
19 -> 1
20 -> 20
21 -> 0
22 -> 23
23 -> 1
24 -> 24
25 -> 0
26 -> 27
27 -> 1
28 -> 28
29 -> 0
30 -> 31
31 -> 1
32 -> 32
33 -> 0
34 -> 35
35 -> 1
36 -> 36
37 -> 0
38 -> 39
39 -> 1
40 -> 40
41 -> 0
42 -> 43
43 -> 1
44 -> 44
45 -> 0
46 -> 47
47 -> 1
48 -> 48
49 -> 0
50 -> 51
51 -> 1
52 -> 52
53 -> 0
54 -> 55
55 -> 1
56 -> 56
57 -> 0
58 -> 59
59 -> 1
60 -> 60
61 -> 0
62 -> 63
63 -> 1
64 -> 64
65 -> 0
66 -> 67
67 -> 1
68 -> 68
69 -> 0
70 -> 71
71 -> 1
72 -> 72
73 -> 0
74 -> 75
75 -> 1
76 -> 76
77 -> 0
78 -> 79
79 -> 1
80 -> 80
81 -> 0
82 -> 83
83 -> 1
84 -> 84
85 -> 0
86 -> 87
87 -> 1
88 -> 88
89 -> 0
90 -> 91
91 -> 1
92 -> 92
93 -> 0
94 -> 95
95 -> 1
96 -> 96
97 -> 0
98 -> 99
99 -> 1
所以规律显然意见,每四个数是0,i+1,1,i
,直接输出就行
代码
#include <bits/stdc++.h>
#define maxOf(a) *max_element(a.begin(),a.end())
#define minOf(a) *min_element(a.begin(),a.end())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;void solve()
{ll n;scanf("%lld",&n);if(n%4==0){printf("%lld\n",n);}else if(n%4==1){printf("0\n");}else if(n%4==2){printf("%lld\n",n+1);}else{printf("1\n");}
}int main()
{int T=1;scanf("%d",&T);while(T--){solve();}return 0;
}