Codeforces Round #674 (Div. 3) E. Rock, Paper, Scissors ###K //K

题目链接:https://codeforces.ml/problemset/problem/1426/E
题意:A出石头a1次,出剪刀a2次,出布a3

B出石头b1次,出剪刀b2次,出布b3

问Alice最少赢多少次,最多赢多少次。

思路: 要不赢的情况 有平局和输掉 但是因为这是一个环所以并不能贪心来确定怎么最优

所以考虑直接枚举所有的情况, 可以得到六种所有输掉的情况 那么答案不同的时候就是这六种

情况顺序不同的时候 所以用next permutation 来得到六种情况的顺序 剩下的场数就是输的场数

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define pb push_back
 4 #define ll long long
 5 const int maxn=1e5+10;
 6 const int mod=1e9+7;
 7 int a[4],b[4],c[4],d[4];
 8 
 9 
10 int ans1=2e9;
11 int ans2=0;
12 
13 
14 int main()
15 {
16     ios::sync_with_stdio(0);
17     cin.tie(0);
18     int n;
19     cin>>n;
20     for(int i=1;i<=3;i++)
21     {
22         cin>>a[i];
23     }
24     for(int i=1;i<=3;i++)
25         cin>>b[i];
26     vector<pair<int,int>>cnt;
27     cnt.pb({1,1});
28     cnt.pb({1,3});
29     cnt.pb({3,3});
30     cnt.pb({3,2});
31     cnt.pb({2,2});
32     cnt.pb({2,1});
33     sort(cnt.begin(),cnt.end());
34     do
35     {
36         for(int i=1;i<=3;i++)
37             c[i]=a[i],d[i]=b[i];
38         for(auto &v:cnt)
39         {
40             int temp=min(c[v.first],d[v.second]);
41             c[v.first]-=temp;
42             d[v.second]-=temp;
43         }
44         int sum=c[1]+c[2]+c[3];
45         ans1=min(ans1,sum);
46     }
47     while(next_permutation(cnt.begin(),cnt.end()));
48     ans2=min(a[1],b[2])+min(a[2],b[3])+min(a[3],b[1]);
49     cout<<ans1<<" "<<ans2<<'\n';
50 }
View Code

 

posted @ 2020-11-20 19:21  canwinfor  阅读(112)  评论(0)    收藏  举报