A.
模拟
// Problem: A. Everyone Loves to Sleep
// Contest: Codeforces - Codeforces Round 811 (Div. 3)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1714/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
struct node{
int h,m;
}a[N];
bool cmp(node a,node b){
if(a.h!=b.h){
return a.h<b.h;
}
return a.m<b.m;
}
void Lan(){
int n,h,m;
cin>>n>>h>>m;
for(int i=1;i<=n;i++){
cin>>a[i].h>>a[i].m;
if(a[i].h<h || (a[i].h==h && a[i].m<m)){
a[i].h+=24;
}
}
sort(a+1,a+1+n,cmp);
int ans=h*60+m;
int res=a[1].h*60+a[1].m;
if(ans==res){
cout<<0<<" "<<0<<'\n';
return;
}
res-=ans;
if(res%60==0){
cout<<res/60<<" "<<0<<'\n';
}else{
cout<<res/60<<" "<<res%60<<'\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
B.
从后往前遍历一遍即可
// Problem: B. Remove Prefix
// Contest: Codeforces - Codeforces Round 811 (Div. 3)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1714/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N],vis[N];
void Lan(){
int n;
cin>>n;
int mx=0;
for(int i=1;i<=n;i++){
cin>>a[i];
mx=max(mx,a[i]);
}
for(int i=1;i<=(mx+1);i++){
vis[i]=0;
}
for(int i=n;i>=1;i--){
if(!vis[a[i]]){
vis[a[i]]=1;
}else{
cout<<i<<'\n';
return;
}
}
cout<<0<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
C.
简单贪心
// Problem: C. Minimum Varied Number
// Contest: Codeforces - Codeforces Round 811 (Div. 3)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1714/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
int s;
cin>>s;
vector<int> v;
int num=9;
while(s){
if(s>num){
s-=num;
v.push_back(num);
num--;
}else{
v.push_back(s);
break;
}
}
reverse(v.begin(),v.end());
for(auto &i:v){
cout<<i;
}
cout<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
D.
1.
重点
学到了区间覆盖
先暴力枚举有几个可以覆盖
然后贪心
找最长的线段去覆盖
认定左边都是被上一个覆盖过了,所以只要枚举右边线段即可
因为写的是while所以我玄学了加了一个计时器如果超过1000就说明不存在方案即可
debug...
2.
dp
// Problem: D. Color with Occurrences
// Contest: Codeforces - Codeforces Round 811 (Div. 3)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1714/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 1e5 + 9;
int dp[N],pre[N];
pair<int,int>a[N];
string ss[N];
void Lan(){
string t;
cin>>t;
int m=t.length();
t=" "+t;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>ss[i];
}
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
int mx=dp[1];
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(i>=ss[j].length()){
if(t.substr(i-ss[j].length()+1,ss[j].length())==ss[j]){
for(int l=(int)(i-ss[j].length());l<i;l++){
if(dp[l]+1<dp[i]){
dp[i]=dp[l]+1;
pre[i]=l;
a[i]={i-ss[j].length()+1,j};
}
}
}
}
}
}
if(dp[m]==mx){
cout<<-1<<'\n';
}else{
cout<<dp[m]<<'\n';
int now=m;
while(now){
cout<<a[now].second<<" "<<a[now].first<<'\n';
now=pre[now];
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
E.
找规律举几个数字
// Problem: E. Add Modulo 10
// Contest: Codeforces - Codeforces Round 811 (Div. 3)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1714/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
//发现有5和没5倍数在一起就不可能
//其他就抽成只有2,然后这样变化就+20,mod20看最后数字是不是一样即可
int work(int x){
while(x%10!=2 && x%10!=0){
x=x+x%10;
}
return x;
}
void Lan(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int cnt=0;
for(int i=1;i<=n;i++){
if(a[i]%5==0){
cnt++;
}
}
if(cnt>0 && cnt<n){
cout<<"No"<<'\n';
return;
}
for(int i=1;i<=n;i++){
a[i]=work(a[i]);
}
if(!cnt){
for(int i=1;i<=n;i++){
a[i]%=20;
}
}
for(int i=1;i<=n-1;i++){
if(a[i]!=a[i+1]){
cout<<"No"<<'\n';
return;
}
}
cout<<"Yes"<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}