Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

题意:

你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最多上一次,所有客人菜单不能相同。给出三种菜的数量,问最多能接收多少客人。

思路:

一人一道 → 一人两道 → 一人三道。

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--){
int a[3];for(int &i:a) cin>>i;
int ans=0;
for(int i=0;i<3;i++)
if(a[i]) --a[i],++ans;
sort(a,a+3,greater<int>());
for(int i=0;i<3;i++)
if(a[i]&&a[(i+1)%3])
--a[i],--a[(i+1)%3],++ans;
if(a[0]&&a[1]&&a[2]) ++ans;
cout<<ans<<endl;
}
return 0;
}

拓展:

你疫情在家闲的没事干多学做了几道菜。

#include <bits/stdc++.h>
using namespace std; const int M=3;//会做几种菜 int a[M],ans;
vector<int> index; bool ok(){
for(int &i:index)
if(a[i]==0) return false;
return true;
} void dfs(int start,int dep,int max_dep){
if(dep>max_dep){
if(ok()){
for(int &i:index) --a[i];
++ans;
}
return;
}
for(int i=start;i<M;i++)
if(a[i]){
index.push_back(i);
dfs(i+1,dep+1,max_dep);
index.pop_back();
}
} void solve(){
for(int &i:a) cin>>i;
sort(a,a+M,greater<int>());
ans=0;
for(int i=0;i<M;i++)
dfs(0,0,i);
cout<<ans<<endl;
} int main()
{
int t;cin>>t;
while(t--)
solve();
return 0;
}

Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)的更多相关文章

  1. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

    Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...

  2. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  3. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  4. Codeforces Round #622 (Div. 2) 1313 A

    Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...

  5. Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)

    第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...

  6. Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治

    题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...

  7. Codeforces Round #622 (Div. 2) 1313 B Different Rules

    B. Different Rules Nikolay has only recently started in competitive programming, but already qualifi ...

  8. Codeforces Round #622(Div 2) C1. Skyscrapers (easy version)

    题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来 ...

  9. Codeforces Round #622 (Div. 2) C2 - Skyscrapers (hard version) 单调栈

    从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long ...

随机推荐

  1. PHP 清除缓存文件

    /*清除缓存文件*/ public function clearRuntime() { $this->delFileByDir(RUNTIME_PATH); $this->success( ...

  2. 从Java的字符串池、常量池理解String的intern()

    前言 逛知乎遇到一个刚学Java就会接触的字符串比较问题: 通常,根据"==比较的是地址,equals比较的是值"介个定理就能得到结果.但是String有些特殊,通过new Str ...

  3. 四:WEB源码扩展

    前言:WEB源码在安全测试中是非常重要的信息来源,可以用来进行代码审计漏洞也可以用来做信息突破口,其中WEB源码有很多技术需要简明分析,获取某ASP源码后就可以采用默认数据库下载为突破,获取某其他脚本 ...

  4. myisam崩溃后发生损坏的概率比innodb高的原因

    myisam崩溃后发生损坏的概率比innodb高的原因

  5. 【Linux】fio测试读写速度

    需要安装fio yum install fio -y 有很多依赖包     FIO用法: 随机读:(可直接用,向磁盘写一个2G文件,10线程,随机读1分钟,给出结果) fio -filename=/h ...

  6. C语言补码(C语言学习笔记)

    记录 在学习C语言数据范围时了解到了补码的概念,记录一下什么是补码,补码怎么运算的 运算 原文链接:https://www.cnblogs.com/lsgsanxiao/p/5113305.html ...

  7. 国人之光:大数据分析神器Apache Kylin

    一.简介 Apache Kylin是一个开源的.分布式的分析型数据仓库,提供Hadoop/Spark 之上的 SQL 查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由 eBay 开发并贡献 ...

  8. Poj-P2533题解【动态规划】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=2533 题目描述: 如果ai1 < ...

  9. 入门OJ:郭嘉的消息传递

    题目描述 我们的郭嘉大大在曹操这过得逍遥自在,但是有一天曹操给了他一个任务,在建邺城内有N(<=1000)个袁绍的奸细 将他们从1到N进行编号,同时他们之间存在一种传递关系,即若C[i,j]=1 ...

  10. three.js cannon.js物理引擎地形生成器和使用指针锁定控件

    今天郭先生说一说使用cannon.js物理引擎绘制地形和使用指针锁定控件.效果如下图.线案例请点击博客原文. 这里面的生成地形的插件和指针锁定控件也是cannon.js的作者schteppe封装的,当 ...