zoukankan      html  css  js  c++  java
  • 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;
    }
    

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

  • 相关阅读:
    WorkerMan中php后端及时推送消息给客户端
    解析Laravel框架下的Contracts契约
    如何在 Laravel 中使用 Slack 进行异常通知
    用户异常与模拟异常的派发
    [IDA] 将变量索引进行计算
    [反汇编]栈帧中函数的参数传入位置
    用户模拟异常的记录
    [反汇编]函数开始部分利用mov ebx,esp找到返回地址(_KTRAP_FRAME结构)
    [反汇编] 获取上一个栈帧的ebp
    CPU异常分析(以trap00为例)
  • 原文地址:https://www.cnblogs.com/Crossea/p/13210847.html
Copyright © 2011-2022 走看看