2022杭电暑期第三场个人题解

签到题

#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define endl '\n'
char str[100005];
void solve() {
	scanf("%s",str);
	if(s[0]=='k') cout<<"KK"<<endl;
	if(s[0]=='d') cout<<"DDW"<<endl;
	else cout<<"SMWY"<<endl; 
}
int main() {
	int t;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;
} 

快递

部分调试代码没删去,不能保证ac

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define ll long long 
#define endl '\n'

struct node{
	int l,r;
}qj[1000005];
int n,k;
bool cmp (node x,node y) {
	if(x.l!=y.l) return x.l<y.l;
	else return x.r>y.r; 
}
bool check(node x,node y) {
	if(max(x.l,y.l) <= min(x.r,y.r))
	return true;
	else {
		cout<<"max is "<<max(x.l,y.l)<<endl;
		cout<<"min is "<<min(x.r,y.r)<<endl<<endl;
		return false; 
	}
} 


void solve() {
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>qj[i].l>>qj[i].r;
	sort(qj+1,qj+1+n,cmp);
	int ans=0;
	for(int i=1;i<=n;) {
		bool ok = 1;
		int j=1;
		int temp=1;
		if(!check(qj[1],qj[4])) cout<<"here!"<<endl;
		if((!check(qj[i],qj[i+1])) && (!check(qj[i],qj[i-1])) && 1){
			ans++;
			i+=1;
			continue;
		}
		while(ok) {
			if(check(qj[i],qj[i+j]) && i+j<=n && 1) {
				cout<<"yes"<<endl;
				temp++;
				j++;
			}else ok = false ;
		}
		i+=j;
		if(temp%k==0) ans+=temp/k;
		else if(temp>k) {
			ans+=temp/k;
			i-=temp%k;
		}  
		else if(temp<k) ans++;
	}
	cout<<ans<<endl;
}
signed main() {
	ios::sync_with_stdio(0),cin.tie(0)	;
	int t;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;
} 

1011

区间排序,可以理解为贪心

#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define endl '\n'

struct node{
	int x,y,w;
}ma[100005];
void solve() {
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++) {
		cin>>ma[i].x>>ma[i].y>>ma[i].w;
	} 
	for(int i=1;i<=q;i++) {
		int x,y;
		cin>>x>>y;
		int ans=0,tt=10000000;
		for(int j=1;j<=n;j++) {
			tt = min(abs(ma[j].x-x)+abs(ma[j].y-y),ma[j].w);
			ans = max(tt,ans);
		}
		cout<<ans<<endl; 
	}
}
int main() {
	ios::sync_with_stdio(0),cin.tie(0)	;
	int t;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值