枚举+组合数?+DP+数学问题


  http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582

  QAQ许久没打过比赛,来一发BC,结果还是只能做前两题……too young too naive了……

  不过这场比赛前两题被hack&FST的人挺多的?蒟蒻手太慢,造数据也慢,玩不来hack……抢不到QAQ

A

  给5张牌,问最少换多少张可得到同花顺。

  其实是枚举花色,以及最小的是哪张(其实就是枚举换完以后,得到的是哪五张)看手里有多少张是已经得到的= =

  开个have[i][j]表示手里有花色为 i 数字为 j 的牌(其中,如果手里有A,那么1和14都置为true)

  hack点?没啥吧……可能有的同学是看手里连续拥有最大段是多长,比如手里最长的连续牌是123,那ans=2,但是135也是只需要换两张……

 //BestCoder #41 A
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
inline int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e5+,INF=~0u>>;
typedef long long LL;
/******************tamplate*********************/ int a[],b[];
char s[][];
bool have[][];
int main(){
#ifndef ONLINE_JUDGE
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
#endif
int T=getint();
while(T--){
memset(have,,sizeof have);
memset(a,,sizeof a);
memset(b,,sizeof b);
memset(s,,sizeof s);
F(i,,) scanf("%s",s[i]);
F(i,,) a[i]=s[i][]-'A';
F(i,,){
b[i]=s[i][]-'';
if (s[i][]>) b[i]=b[i]*+s[i][]-'';
have[a[i]][b[i]]=;
if (b[i]==) have[a[i]][]=;
}
#ifdef debug
F(i,,) printf("%d %d\n",a[i],b[i]);
#endif
int ans=;
rep(i,){
int mx=,now=;
F(j,,){
now=now+have[i][j]-have[i][max(j-,)];
mx=max(mx,now);
}
ans=max(ans,mx);
}
printf("%d\n",-ans);
}
return ;
}

B

  一开始看错题了[捂脸熊]

  其实就是问有多少种情况下选出两个字符串你能赢。

  容易发现赢的情况是:两个字符串完全相同;或者两个字符串长度和为奇数。第一种情况只需一次B操作就赢了……第二种情况只要努力拿短的那个,最后一个肯定是你的。

  那么记录一下奇数长度和偶数长度的字符串有多少个,以及每个字符串有多少个与它相同(map大法吼!其实map存的是一个pair……first是key,second就是val)

  然后组合数算一下就好了。(然而蒟蒻在快结束的时候发现记录「有多少个奇/偶长度的字符串」的变量用的是int……而不是像ans一样用的是LL……感觉乘的时候要爆炸啊,果断重交了一发,分数&rank瞬间就下来了……QAQ(不过没有FST&被hack应该还是算赚了吧)

 //BestCoder #41 B
#include<map>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
inline int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e5+,INF=~0u>>;
typedef long long LL;
/******************tamplate*********************/
map<string,int>s;
LL gcd(LL a,LL b){return b ? gcd(b,a%b) : a;}
string s1;
int main(){
#ifndef ONLINE_JUDGE
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
#endif
int T=getint();
while(T--){
s.clear();
LL cnt0=,cnt1=;
LL n=getint();
F(i,,n){
cin >>s1;
if (s1.length()&) cnt1++;
else cnt0++;
if (s.find(s1)!=s.end()) s[s1]=s[s1]+;
else s[s1]=;
}
LL fz=(LL)cnt0*cnt1,fm=n*(n-)/;
for(map<string,int>::iterator it=s.begin();it!=s.end();it++){
LL v=it->second;
fz+=v*(v-)/;
}
LL d=gcd(fz,fm);
printf("%lld/%lld\n",fz/d,fm/d);
}
return ;
}

C

  其实有一道题跟它是很相似的QAQ  【BZOJ】【3612】【HEOI 2014】平衡

  然而蒟蒻没有想到……

  并且这题卡空间!但是又由于有一些特殊性质,可以优化= =

  其实,每个数最多只能拆分成$O(\sqrt{n})$个数,因为有$\frac{x*(x+1)}{2}=n \rightarrow x=2*\sqrt{n}$

  所以其实在转移的时候,i-j 不会很远……所以之前很多的计算结果都不用保留了……所以?滚动数组!

 //BestCoder #41 C
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
inline int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e5+,INF=~0u>>,mod=;
typedef long long LL;
/******************tamplate*********************/
int f[][];
int main(){
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
int T=getint(),n,c,l,r;
f[][]=;
while(T--){
n=getint(); c=getint(); l=getint()-c; r=getint()-c;
LL ans=l==; if (r==n) ans--;
F(i,,r){
int now=i%;
memset(f[now],,sizeof f[now]);
f[now][]=;
for(int j=;j*(j+)/<=i;j++){
int fa=now-j;
if (fa<) fa+=;
f[now][j] = f[fa][j]+f[fa][j-];
if (f[now][j]>=mod) f[now][j]-=mod;
}
if (i>=l)
for(int j=;j*(j+)/<=i;j++){
ans+=f[now][j];
if (ans>=mod) ans-=mod;
}
}
printf("%lld\n",ans);
}
return ;
}

D

  SXBK的数学题>_>当然是果断弃疗啊……

  

【BestCoder】【Round#41】的更多相关文章

  1. LeetCode:缺失的第一个正数【41】

    LeetCode:缺失的第一个正数[41] 题目描述 给定一个未排序的整数数组,找出其中没有出现的最小的正整数. 示例 1: 输入: [1,2,0] 输出: 3示例 2: 输入: [3,4,-1,1] ...

  2. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  3. 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)

    cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...

  4. 【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog

    [链接] 我是链接,点我呀:) [题意] [题解] 找到度数为1的点. 他们显然是叶子节点. 然后每个叶子节点. 往上进行bfs. 累计他们的父亲节点的儿子的个数. 如果都满足要求那么就继续往上走. ...

  5. 【cf补题记录】Codeforces Round #608 (Div. 2)

    比赛传送门 再次改下写博客的格式,以锻炼自己码字能力 A. Suits 题意:有四种材料,第一套西装需要 \(a\).\(d\) 各一件,卖 \(e\) 块:第二套西装需要 \(b\).\(c\).\ ...

  6. 【iScroll源码学习04】分离IScroll核心

    前言 最近几天我们前前后后基本将iScroll源码学的七七八八了,文章中未涉及的各位就要自己去看了 1. [iScroll源码学习03]iScroll事件机制与滚动条的实现 2. [iScroll源码 ...

  7. 【iScroll源码学习01】准备阶段 - 叶小钗

    [iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文  http://www.cnblogs.com/yexiaochai/p/3 ...

  8. 【Ruby】【基础】

    # [Ruby 块]=begin1 块由大量代码构成2 块中代码包含在{}内3 从与其相同名称的函数调用4 可以使用yield语句调用块=enddef test p '在test方法内' yield ...

  9. 【ASP.NET程序员福利】打造一款人见人爱的ORM(二)

    上一篇我已经给大家介绍AntORM的框架[ASP.NET程序员福利]打造一款人见人爱的ORM(一),今天就来着重介绍一下如何使用这套框架 1>AntORM 所有成员 如果你只想操作一种数据库,可 ...

随机推荐

  1. bzoj 1826

    思路:贪心取最后出现的. #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...

  2. shell rename directory

    mv can do two jobs. It can move files or directories It can rename files or directories To just rena ...

  3. NetCore+Dapper WebApi架构搭建(六):添加JWT认证

    WebApi必须保证安全,现在来添加JWT认证 1.打开appsettings.json添加JWT认证的配置信息 2.在项目根目录下新建一个Models文件夹,添加一个JwtSettings.cs的实 ...

  4. 1011 World Cup Betting (20)(20 point(s))

    problem With the 2010 FIFA World Cup running, football fans the world over were becoming increasingl ...

  5. MyBatis之MyBatis环境搭建

    MyBatis之MyBatis环境搭建 一.MyBatis开发环境搭建 1.引入Jar包 ①MyBatis mybatis-3.4.1.jar ant-1.9.6.jar ant-launcher-1 ...

  6. [BZOJ5305][HAOI2018]苹果树(DP)

    首先注意到每种树都是等概率出现的,于是将问题转化成计数求和问题. f[n]表示所有n个点的树的两两点距离和的总和. g[n]表示所有n个点的树的所有点到根的距离和的总和. h[n]表示n个点的树的可能 ...

  7. Codeforces Round #279 (Div. 2) B - Queue 水题

    #include<iostream> #include<mem.h> using namespace std; ],q[]; int main() { int n,x,y; m ...

  8. C#中常见的系统内置委托用法详解(抄录)

    C#中常见的系统内置委托 Action类.Func类.Predicate<T>.Comparison<T>委托 Action类的委托 Action委托 封装一个方法,该方法不具 ...

  9. 无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的COM 对象强制转换为接口类型“Microsoft.Office.Interop.Excel._Application”

    报错内容如下: 无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的COM对象强制转换为接口类型“Microsoft.Office.Inte ...

  10. 云计算大会有感—MapReduce和UDF

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 1.參会有感       首先还是非常感谢CSDN能给我票,让我有机会參加这次中国云计算峰会.感觉不写点什么对不 ...