Google Kickstart Round E 2018 B. Milk Tea
太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误
大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求出没有被禁的最优解即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const ll mod=1e9+;
const int maxn=4e2+;
const int maxm=1e6+;
const double eps=1e-;
int m,n,p;
int ar[maxn];
char c[maxn]; set<pair<int,string> > se;
set<string> seMid; char cha(char c)
{
return c==''?'':'';
}
int main()
{
fopen
int t,fir=;scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&p);
memset(ar,,sizeof(ar));
seMid.clear();
se.clear();
for(int i=;i<n;i++){
scanf("%s",c);
for(int j=;j<p;j++){
if(c[j]=='')ar[j]++;
}
}
for(int i=;i<m;i++){
scanf("%s",c);
seMid.insert(string(c));
}
string str(p,'');
int mid=;
for(int i=;i<p;i++){
if(ar[i]>n/){
str[i]='';
ar[i]=n-ar[i];
}
mid+=ar[i];
}
se.insert(make_pair(mid,string(str)));
int ans=;
while((int)se.size()<=m){
int mn=p*n;
string ss;
for(set<pair<int,string>>::iterator au = se.begin();au!=se.end();au++){
mid = au->first;
string sMid = au->second;
if(mid>mn)break;
for(int i=;i<p;i++){
if(sMid[i]==str[i] && mn>mid+n-*ar[i]){
sMid[i] = cha(sMid[i]);
if(se.count(make_pair(mid+n-*ar[i],sMid))==){
mn=mid+n-*ar[i];
ss=sMid;
}
sMid[i] = cha(sMid[i]);
}
}
}
se.insert(make_pair(mn,ss));
if(seMid.count(ss)==)break;
}
set<pair<int,string>>::iterator au=se.begin();
for(;au!=se.end();au++){
string sMid = au->second;
if(seMid.count(sMid)==){
ans=au->first;
break;
}
}
printf("Case #%d: %d\n",++fir,ans);
}
return ;
}
Google Kickstart Round E 2018 B. Milk Tea的更多相关文章
- google Kickstart Round G 2017 三道题题解
A题:给定A,N,P,计算A的N!次幂对P取模的结果. 数据范围: T次测试,1 ≤ T ≤ 100 1<=A,N,P<=105 快速幂一下就好了.O(nlogn). AC代码: #inc ...
- Let Me Count The Ways(Kickstart Round H 2018)
题目链接:https://code.google.com/codejam/contest/3324486/dashboard#s=p2 题目: 思路: 代码实现如下: #include <set ...
- 2019 google kickstart round A
第一题: n个人,每个人有一个对应的技能值s,现在要从n个人中选出p个人,使得他们的技能值相同. 显然,如果存在p个人的技能值是相同的,输出0就可以了.如果不存在,就要找出p个人,对他们进行训练,治他 ...
- google Kickstart Round F 2017 四道题题解
Problem A. Kicksort 题意抽象一下为: 对于一个每次都从数列正中间取划分数的快速排序,给定一个1-n的排列,问快排的复杂度对于这个排列是否会退化为最坏复杂度. 数据范围: 测试组数1 ...
- Google Kickstart Round.B C. Diverse Subarray
这题又是万恶的线段树 maxx[j]存储的是 l = xxx, r = j的时候的答案 我们会让 l 从 1到n 的遍历中,查询线段树的[l, n]中最大的答案 因为query的下界是n,所以单次查询 ...
- Kickstart Round H 2018
打了ks好久都没有更新 诶,自己的粗心真的是没救了,A题大数据都能错 A #include <iostream> #include <cstdio> #include < ...
- Kickstart Round G 2018
第一次打codejam....惨的一比,才A1.5题,感觉自己最近状态渣到姥姥家了,赶紧练练 A 模拟,注意0的问题 #include <iostream> #include <cs ...
- Google Kickstart在线测试规则以及注意事项
谷歌招聘在如火如荼的进行中,进谷歌都需要经过谷歌kickstart在线测试,然后过了之后还有五轮的面试- -.好吧毕竟你待遇高,你强你有理.. 下面介绍一下进谷歌的第一关google kickstar ...
- HDU 6667 Roundgod and Milk Tea (思维)
2019 杭电多校 8 1011 题目链接:HDU 6667 比赛链接:2019 Multi-University Training Contest 8 Problem Description Rou ...
随机推荐
- wget下载https文件,服务器可以虚拟机中不行的问题
用wget下载一个图片资源(https协议),在服务器上可以,但在本机的虚拟机中卡在下面这里了: [root@localhost ~]# wget 'https://gp1.wac.edgecastc ...
- leetcode 【 Remove Duplicates from Sorted List II 】 python 实现
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...
- 常用模块(sys)
import sys# sys.argv() # 命令参数List,第一个元素是程序本身路径,如:python test.py run db# sys.exit('shh') # 退出程序,正常退出时 ...
- pdb在python程序中应用
1.什么是pdb? pdb是python提供的调试程序的一种工具. 2.为什么需要pdb模块? 当我们的程序越写越大的时候,我们用print xxx 这种方式打断点,调试,非常不方便,这个时候我们需要 ...
- protobuf-net与FlatBuffers
protobuf-net Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法.它比xml格式要少的多,甚至比二进制数据格式也 ...
- pytorch下对简单的数据进行分类(classification)
看了Movan大佬的文字教程让我对pytorch的基本使用有了一定的了解,下面简单介绍一下二分类用pytorch的基本实现! 希望详细的注释能够对像我一样刚入门的新手来说有点帮助! import to ...
- Vue打包app
前言 公司之前用的app就是一个套壳挂个链接就能用的app,后来需要添加微信分享方便传播,没办法只好做成混合式的app了, 因为之前做.net用vs可以创建cordova项目也试着玩过,就决定用cor ...
- excel模板解析—桥接模式:分离解析模板和业务校验
在做excel模板解析的时候,其实会有两个部分,第一,将模板读取出来,校验一些必录项等. 但除了这些,在数据真正被业务线使用的时候,还会有一些其他的校验,比如说:根据业务,年龄是不能超过多少岁的,包括 ...
- 使用common-fileUpload实现文件上传
通过common-fileUpload文件上传组件,可以实现上传文档.图片等资料.根据程序的不同要求,它可以有多种方式的应用. 我们这里介绍一种简单的例子,来实现文件上传功能. 准备: 引入相关组建的 ...
- 从 C10K 到 C500K
国外的 Urban Airship 公司的工程师在其官方网志上发文章介绍他们在产品环境中做到 50 万并发客户端,Java + Pure NIO 的实现,最近又有文章介绍针对 Linux Kernel ...