zoukankan      html  css  js  c++  java
  • E. Cheap Dinner from Educational Codeforces Round 104 (Rated for Div. 2)

    题意:有4种菜,每种菜有n1,n2,n3,n4个,每个菜有一个价格。

    需要你每种菜选1个,问最小价格。但1和2、2和3、3和4之间有些菜有1对1的互斥关系,如果有互斥则不能选。

    做法:把每两组贪心线性预处理,最后合并即可

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define pll pair<ll,ll>
    #define pii pair<int,int>
    #define vll vector<ll>
    #define vpll vector<pll>
    #define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    double pi = acos(-1);
    const double eps = 1e-9;
    const int inf = 1e9 + 7;
    const ll lnf = 1e18 + 7;
    const int maxn = 2e5+ 10;
    ll mod = 1e9 + 7;
    
    int head[maxn], edge_cnt = 0;
    
    struct edge {
    	int to, next;
    }e[maxn << 1];
    
    inline void add(int from, int to)
    {
    	e[++edge_cnt] = { to,head[from] };
    	head[from] = edge_cnt;
    }
    struct Node
    {
    	int vue;
    	int id;
    	friend bool operator < (Node x,Node y)
    	{
    		return x.vue < y.vue;
    	}
    }a[5][maxn];
    
    set<int>s[5][maxn];
    
    int main()
    {
    	fastio;
    		int n1, n2, n3, n4;
    		cin >> n1 >> n2 >> n3 >> n4;
    		for (int i = 1; i <= n1; i++)cin >> a[1][i].vue,a[1][i].id=i ,s[1][i].clear();
    		for (int i = 1; i <= n2; i++)cin >> a[2][i].vue,a[2][i].id=i ,s[2][i].clear();
    		for (int i = 1; i <= n3; i++)cin >> a[3][i].vue,a[3][i].id=i ,s[3][i].clear();
    		for (int i = 1; i <= n4; i++)cin >> a[4][i].vue,a[4][i].id=i ,s[4][i].clear();
    
    		int m;
    		cin >> m;
    		while (m--)
    		{
    			int x, y;
    			cin >> x >> y;
    			s[1][y].insert(x);
    		}
    		cin >> m;
    		while (m--)
    		{
    			int x, y;
    			cin >> x >> y;
    			s[2][y].insert(x);
    		}
    		cin >> m;
    		while (m--)
    		{
    			int x, y;
    			cin >> x >> y;
    			s[3][y].insert(x);
    		}
    		sort(a[1] + 1, a[1] + n1 + 1);
    		for (int i = 1; i <= n2; i++)
    		{
    			bool flag = 0;
    			for (int cnt = 1; cnt <= n1; cnt++)
    			{
    				int id = a[1][cnt].id;
    				if (s[1][i].find(id) == s[1][i].end())
    				{
    					a[2][i].vue += a[1][cnt].vue;
    					flag = 1;
    					break;
    				}
    			}
    			if (!flag)a[2][i].vue = inf;
    		}
    		sort(a[2] + 1, a[2] + n2 + 1);
    		for (int i = 1; i <= n3; i++)
    		{
    			bool flag = 0;
    			for (int cnt = 1; cnt <= n2; cnt++)
    			{
    				int id = a[2][cnt].id;
    				if (a[2][cnt].vue == inf)break;
    				if (s[2][i].find(id) == s[2][i].end())
    				{
    					a[3][i].vue += a[2][cnt].vue;
    					flag = 1;
    					break;
    				}
    			}
    			if (!flag)a[3][i].vue = inf;
    		}
    		sort(a[3] + 1, a[3] + n3 + 1);
    		int ans = inf;
    		for (int i = 1; i <= n4; i++)
    		{
    			bool flag = 0;
    			for (int cnt = 1; cnt <= n3; cnt++)
    			{
    				if (a[3][cnt].vue == inf)break;
    				int id = a[3][cnt].id;
    				if (s[3][i].find(id) == s[3][i].end())
    				{
    					a[4][i].vue += a[3][cnt].vue;
    					flag = 1;
    					break;
    				}
    			}
    			if (flag)ans = min(ans, a[4][i].vue);
    		}
    		if (ans == inf)
    			cout << -1 << endl;
    		else cout << ans << endl;
    
    	return 0;
    
    }
    
  • 相关阅读:
    使用 HtmlInputHidden 控件在本页面保持状态和跨页面传值
    asp.net页面回传与js调用服务端事件、PostBack的原理详解
    关于.net委托的一篇妙文
    C# 基础25问
    存储过程分页
    C#中的格式化字符串
    大批量数据的插入之终极性能提升SqlBulkCopy
    统计某个字符串中指定字符串出现的次数
    powerdesigner 15打开pdm文件弹出安装打印机窗口的解决方法
    Convert.ToInt32(),Int.Parse(),Int.TryParse()的区别
  • 原文地址:https://www.cnblogs.com/ruanbaiQAQ/p/14429230.html
Copyright © 2011-2022 走看看