Codeforces Round #811 (Div. 3) (A B C E题解)

A题链接

题目大意:
n , h n,h nh m m m 分别代表n个闹钟和当前时间。
接下来 n n n 行分别是 h i h_i hi m i m_i mi
问这个人最多能睡多久,每一个闹钟都可以视为周期为每天的闹钟。

题解思路:
其实,最简单的方法是:
把当前时间的 h h h m m m 全部转变成今天过去了多少分钟 M M M,即 h ∗ 60 + m h*60+m h60+m,然后把每一个 h i h_i hi m i m_i mi 都同理转变 k k k,接下来,如果 M ≤ k M ≤ k Mk ,就让 a n s = m i n ( a n s , k − M ) ans=min(ans,k-M) ans=minanskM,否则就让 a n s = m i n ( a n s ,( 60 ∗ 24 + k − M )) ans=min(ans,(60*24+k-M)) ans=minans,(6024+kM)),然后输出 a n s / 60 ans/60 ans/60 a n s ans%60 ans 就行。

但是我的做法是,用 p a i r pair pair 存了 a n s ans ans h h h m m m ,然后进行比较,脑子好像有什么病一样。

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
using namespace std;
 
void solve()
{
	int n,h,m;
	cin>>n>>h>>m;
	int k=h*60+m;
	PII ans;
	ans.x=INF,ans.y=INF;
	rep(i,1,n)
	{
		int a,b;
		cin>>a>>b;
		int num=a*60+b;
		if(num>=k)
			num-=k;
		else 
			num+=24*60-k;
			
		int q=num/60,w=num%60;
		if(q<ans.x)
			ans.x=q,ans.y=w;
		else if(q==ans.x)
			ans.y=min(ans.y,w);
	}
	
	cout<<ans.x<<" "<<ans.y<<endl;
}

B题链接

题目大意:
从左端点开始,依次删除任意数量的数字,让剩下的序列没有重复的字符

解题思路:
从右端点开始枚举,然后放 m a p map map 里面,如果 m a p map map 里面已经出现过了,就把当前点及之前的全删除掉就可以了,因为我数组是从1开始的,所以从枚举的时候直接输出i就可以了。

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
using namespace std;
 
const int N=2e5+10;
int a[N];
 
void solve()
{
	int n;
	cin>>n;
	rep(i,1,n)
		cin>>a[i];
	map<int,int> mp;
	dec(i,n,1)
	{
		if(mp[a[i]])
		{
			cout<<i<<endl;
			return;
		}
		mp[a[i]]++;
	}
	cout<<0<<endl;
}

C题链接

题目大意:
给一个数字 n n n n n n 是一个数字k每一位的和(且每一位都是不一样的),输出最小的数字k。

解题思路:
一开始,我是想dfs做的,但是,在我gank掉两只蚊子之后我发现,从 9 9 9 开始枚举就可以,这样高位肯定是最小的,所以我写出来一下的解题思路:

从最低位开始枚举,每一位从 9 9 9 1 1 1 开始枚举,如果n≥当前数字同时这个数字之前没用过,就放ans里,然后倒序输出即可。

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
using namespace std;
 
vector<int> ans;
 
void solve()
{
	int n;
	cin>>n;
	map<int,int> mp;
	while(n)
	{
		dec(i,9,1)
		{
			if(n>=i&&!mp[i])
			{
				mp[i]++;
				n-=i;
				ans.pb(i);
				break;
			}
		}
	}
	dec(i,ans.size()-1,0)
		cout<<ans[i];
	cout<<endl;
	ans.clear();
}

E题链接

题目大意:
每一个 a i a_i ai 可以进行任意次数的操作,可以把 a i a_i ai 变成 a i + a i m o d    10 a_i+a_i\mod10 ai+aimod10
问能不能让一个序列变成一样的

解题思路:
打表可以发现
① 1 2 4 8 16 22 24.。。。。这样形成了一个个位数循环的序列
②3 6 12 14 18 26。。。这样也是一个循环序列
③ 7 14 18.。。这个序列和②连起来了
④ 9 18.。。这个序列也和②连起来了
⑤5 10 10.。。。这个序列。。。我不好说

综上,可以发现大致可以分为三类,一是5和10这一类,二是①这一类,三是序列②。

但是序列二和序列三如何区分呢?都把个位数变成2就好了,序列二中,个位数变成2之后,十位数是偶数,序列三是奇数。

代码如下:

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define dec(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
#define pb push_back
#define LL long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define pi acos(-1)
using namespace std;
 
const int N=2e5+10;
int a[N];
 
void solve()
{
	int n;
	cin>>n;
	
	int n1=0,n2=0;
	
	rep(i,1,n)
	{
		cin>>a[i];
		if(a[i]%10==0||a[i]%10==5)
			n1++;
		else n2++;
	}
	
	if(!n2)
	{
		rep(i,1,n)
			if(a[i]%10==5)
				a[i]+=5;
		sort(a+1,a+1+n);
		if(a[1]==a[n]) cout<<"YES\n";
		else cout<<"NO\n";
	}
	else if(n1&&n2) cout<<"NO\n";
	else
	{
		n1=n2=0;
		
		rep(i,1,n)
		{
			while(a[i]%10!=2)
			{
//				cout<<a[i]<<endl;
				a[i]+=a[i]%10;
			}
				
			if(a[i]/10%2!=0)
				n1++;
			else n2++;
		}
		if(n1>0&&n2>0) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

woc,寄了,烧一天了,下午还打了牛子(不会马拉车,艰难四题,还发现牛子群炸了),晚上打cf,一直脑子一直在抽抽。

虽然很sad,但是unr不掉分,哈哈哈哈!!!
(其他题目等发烧好了再补。)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值