XTUOJ 1246 Heartstone 贪心
2016-06-16 10:37
260 查看
题意:挺好懂得
分析:先计算出如果不能用(减2)操作,至少需要多少个(减3)操作,这个很好计算
然后就是尽量多的去减少(减3)操作,肯定先抹平 余2 和 余1 的,然后就可以了
View Code
分析:先计算出如果不能用(减2)操作,至少需要多少个(减3)操作,这个很好计算
然后就是尽量多的去减少(减3)操作,肯定先抹平 余2 和 余1 的,然后就可以了
#include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; const int N=1e5+5; const int INF=0x3f3f3f3f; const int mod=1e9+7; int f ,a ,d[6]; int main() { int n,m; while(~scanf("%d%d",&n,&m)){ memset(d,0,sizeof(d)); int sum=0,c=0; for(int i=1;i<=n;++i){ scanf("%d",&a[i]); ++d[a[i]%6]; sum+=a[i]/6; if(a[i]%6==1){ if(a[i]>6)++c; } } int ret=0; for(int i=0;i<=m;++i){ int ans; if(i<=d[1]+d[2]+d[4]+d[5]){ ans=d[1]+d[2]+d[4]+d[5]-i+d[4]+d[5]+d[3]+sum*2; } else { int k[6]; for(int j=1;j<=5;++j)k[j]=d[j]; k[2]=k[4];k[4]=0; k[3]+=k[5];k[5]=0; k[1]=0; int tmp=sum-c; k[2]+=c;k[3]+=c; int t=i-d[1]-d[2]-d[4]-d[5]; if(t<=k[2]){ k[2]-=t; ans=tmp*2+k[2]+k[3]; } else { t-=k[2];k[2]=0; int p=t/3; if(tmp<=p){ p-=tmp; tmp=0; } else tmp-=p,p=0; t=t%3+p*3; t/=2; ans=max(0,tmp*2+k[3]-t); } } ret=(ret+ans)%mod; } printf("%d\n",ret); } return 0; }
View Code
相关文章推荐
- linux中利用sandbox自动安装MySQL
- public/private/protected的具体区别
- Oracle 多表查询
- “机器学习”相关资料分享
- 微信表情的字符编号完整版【图文并茂哦!】
- 获得浏览器版本信息
- VB.net学习笔记(三十)认识线程池
- Hadoop2.2.0安装配置手册!完全分布式Hadoop集群搭建过程~(心血之作啊~~) .
- UIDynamic
- 九度OJ 1061 成绩排序
- SQLSERVER 远程登录18456错误
- android 删除sd卡某个目录下的所有文件
- 避免table的border重叠变粗,只需要对table的css设定border-collapse:collapse; 可以解决
- Android ViewPager + Fragment的使用
- ffmpeg 安装 分割 截图 转换 加水印
- 判断点在凸四边形内
- 3对符合条件的文件和文件夹进行复制或修改
- lucene搜索报错排查记录
- Linux 上四个最佳的现代开源代码编辑器
- 最近那些事