Codeforces Round #653 (Div. 3) A~E1

减去y,相除, 直接求
--

#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()


int main(int argc, char const *argv[])
{
	// #define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;
	while(_--){
		LL a,b,c;
		cin>>a>>b>>c;
		c-=b;
		LL d = c/a;
		cout<<(d)*a+b<<endl;
	}
	return 0;
}

能通过乘以2和除以6达到1的话,那么必然因子只有3和2,而且因子3的个数不小于2的个数


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()


int main(int argc, char const *argv[])
{
	// #define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;
	while(_--){
		LL a;
		cin>>a;
		// 2和3分别有几个
		LL c2 = 0;
		LL c3 = 0;
		while(a && a%2==0)  c2++, a/=2;
		while(a && a%3==0) c3++, a/=3;
		// 肯定起码有一个三吧
		// cout<<c2<<" "<<c3<<" "<<a<<endl;
		if(a!=1||c2>c3)
			cout<<-1<<endl;
		else
			cout<<c3*2-c2<<endl;

	}
	return 0;
}

贪心来做,已经配对的括号肯定不动,然后错位的就只要挪一个就肯定能导致多一个配对的
直接扫一遍就可以


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()


int main(int argc, char const *argv[])
{
	#define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;
	while(_--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		//配对的肯定不用管吧
		//逆序的就要挪,看有多少是配对的就行
		int l = 0;
		for(int i=0; i<n; i++){
			if(s[i]=='(')
				l++;
			else
				l = max(0, l-1);
		}
		cout<<l<<endl;
	}
	return 0;
}

先对所有的数取模,看需要加几,如果一个数需要m次
那么ans起码就要要跳到m*(k-1) + need

#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()


int main(int argc, char const *argv[])
{
	// #define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	LL _;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>_;
	while(_--){
		// 无论做什么,反正都是x要加1的

		int n,k;
		cin>>n>>k;
		int x;
		map<int, int> mp;
		rep(i,0,n){
			cin>>x;
			if(x%k==0)
				continue;
			mp[k-x%k] += 1;
		}
		LL ans=0;
		for(auto e:mp){
			ans = max(ans, (LL)(e.se-1)*k+e.fi+1);
		}
		cout<<ans<<endl;
	}
	return 0;
}

应该也是贪心吧,思路就是先按时间排序
然后建立两个链表把仅对一个贡献的放到链表里
这里偷懒直接放到优先队列里,遇到一个对两者
都有贡献而且有一个人已经超了的时候看能不能
去掉前面已经选了的来优化结果

#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()

struct Book
{
	int t;
	int al, bo;
	Book(){};
	Book(int t, int alice, int bob): t(t), al(alice),bo(bob){};
	friend bool operator<(const Book& a, const Book& b){
		return a.t<b.t;
	}
};
int main(int argc, char const *argv[])
{
	// #define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a=0, b=0;
	int n,k;
	cin>>n>>k;
	int t, al, bo;
	vector<Book> book;
	rep(i, 0, n){
		cin>>t>>al>>bo;
		a += al;
		b += bo;
		if(!(al||bo))
			continue;
		book.pb(Book(t, al, bo));
	}
	if(a<k||b<k){
		cout<<-1<<endl;
		return 0;
	}
	priority_queue<Book> quea;
	priority_queue<Book> queb;
	sort(all(book));
	int ans=0;
	a=0, b=0;
	for(int i=0; i<(int)book.size(); i++){
		if(book[i].al&&book[i].bo){
			// 不是最多的就直接选吧
			if(a>=k&&b>=k){
				//尝试能不能换掉?
				if(quea.empty()||queb.empty())
					break;
				int cost=0;
				cost += quea.top().t;
				quea.pop();
				cost += queb.top().t;
				queb.pop();
				if(book[i].t>=cost)
					break;
				else{
					ans -= cost;
					ans += book[i].t;
				}
			}else if(a>=k||b>=k){
				int cost = 0;
				if(a>=k&&!quea.empty()){
					cost += quea.top().t;
					a--;
					quea.pop();
				}
				if(b>=k&&!queb.empty()){
					cost += queb.top().t;
					b--;
					queb.pop();
				}
				a++, b++;
				ans -= cost;
				ans += book[i].t;
			}else{
				a++, b++;
				ans += book[i].t;
			}

		}else if(book[i].al){
			if(a>=k)
				continue;
			a++;
			ans += book[i].t;
			quea.push(book[i]);

		}else{
			if(b>=k)
				continue;
			b++;
			ans += book[i].t;
			queb.push(book[i]);
		}
		
	}
	cout<<ans<<endl;
	return 0;
}

今天浙大面试凉凉了┭┮﹏┭┮

猜你喜欢

转载自www.cnblogs.com/Crossea/p/13210847.html