CCPC 2018 吉林 C "JUSTICE" (数学)
参考资料:
[1]:https://blog.csdn.net/mmk27_word/article/details/89789770
题目描述
Put simply, the Justice card represents justice, fairness, truth and the law.You are being called to account for your actions and will be judged accordingly. If you have acted in a way that is in alignment with your Higher Self and for the greater good of others, you have nothing to worry about. However, if you have acted in a way that is out of alignment, you will be called out and required to own up to your actions. If this has you shaking in your boots, know that the Justice card isn't as black and white as you may think.
(以上是故事情节么...........)
On the table there are n weights.
On the body of the i-th weight carved a positive integer ki, indicating that its weight is /(^ki) gram.
Is it possible to divide then weights into two groups and make sure that the sum of the weights in each group is greater or equal to / gram?
That's on your call. And please tell us how if possible. 输入
In the first line of the input there is a positive integer T (≤T≤), indicating there are T testcases.
In the first line of each of the T testcases, there is a positive integer n (≤n≤1e5 , Σ n ≤ ×1e5 ),indicating there areηweights on the table.
In the next line, there are n integers ki (≤ki≤1e9), indicating the number carved on each weight. 输出
For each testcase, first print Case i : ANSWER in one line, i indicating the case number starting from and ANSWER should be either YES or NO, indicating whether or not it is possible to divide the weights. Pay attention to the space between : and ANSWER.
If it's possible, you should continue to output the dividing solution by print a 0 / 1 string of length n in the next line.
The i-th character in the string indicating whether you choose to put the i-th weight in group or group .
题目描述
样例输入 样例输出
Case : NO
Case : YES Case : YES
样例输入输出
题解看上述参考资料,下面谈谈我的进一步理解,以及,比赛时思路出现的错误:
组成一个 1 / 2 需要
21个 22 , 22个23 , ....... , 2x-1个2x;
那么,从幂最小的k向上递推,判断是否存在 x,y 使得 x 出现的次数 ≥ 2x-1 , y 出现的次数 ≥ 2y-1 次;
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e5+; int n;
struct Date
{
int k;
int id;
bool operator < (const Date &obj) const
{
return k < obj.k;
}
}_date[maxn];
int vis[maxn]; void Solve()
{
mem(vis,);
sort(_date+,_date+n+); int k=;
int cnt1=;//2^1只需要一个
int cnt2=;//2^1只需要一个
for(int i=;i <= n;++i)
{
//假设 d=_date[i].k-k
//那么,从需要 cnt*2^d 个_date[i].k
//类乘 d 次就会得到所需的cnt
//此处是不可能超时的
//因为n-i+1 最大才1e5,而2^17 > 1e5,所以,单次最多累加17次
//所以说 cnt1+cnt2 <= n-i+1 很关键
//以及后面的if(cnt1==0 && cnt2==2) break;也很关键
//如果不break,那么这个while中的cnt1+cnt2=0,k最多会加到1e9,指定TLE
while(cnt1+cnt2 <= n-i+ && k < _date[i].k)
{
cnt1 *= ;
cnt2 *= ;
k++;
}
if(cnt1+cnt2 > n-i+)//这之后没有cnt1+cnt2个数,那,肯定组不成2个1/2
{
puts("NO");
return ;
}
if(cnt1)
{
cnt1--;
vis[_date[i].id]=;
}
else
cnt2--; if(!cnt1 && !cnt2)//关键,去掉会TLE
break;
}
if(cnt1 || cnt2)
puts("NO");
else
{
puts("YES");
for(int i=;i <= n;++i)
printf("%d",vis[i]);
printf("\n");
}
}
int main()
{
int test;
scanf("%d",&test);
for(int kase=;kase <= test;++kase)
{
scanf("%d",&n);
for(int i=;i <= n;++i)
{
scanf("%d",&_date[i].k);
_date[i].id=i;
}
printf("Case %d: ",kase);
Solve();
}
return ;
}
反思总结:
比赛时,看到 n 最大为 1e5 ,而1 / 2k 组成 1 / 2 至少需要 2k-1 个 2k ,然后,找到了2k ≤ 1e5 的最大的 k = 17;
然后,就特判,当 ki > 20 时,就不管;
对于 ki ≤ 20 的情况,定义一个数组a,a[i] : k = i 的 k 的总个数;
每次都更新一遍数组 a;
for(int i=;i >= ;--i)
{
a[i-] += a[i]/;//两个i构成一个i-1
a[i] %= ;
}
最后判断一下a[1]的个数,如果 < 2,输出"NO";
反之,输出"YES",并输出分组;
然后,今天下午debug了一下午,学弟给了我一组数据,顿悟了,debug成功;
当 k > 17 时,也可以组成 1 / 2;

x最大可取1e5,所以说,k最大也可到达1e5;
CCPC 2018 吉林 C "JUSTICE" (数学)的更多相关文章
- CCPC 2018 吉林 H "LOVERS" (线段树)
---恢复内容开始--- 传送门 参考资料: [1]:https://blog.csdn.net/mmk27_word/article/details/89788448 题目描述: The Fool ...
- 2018年中国研究生数学建模竞赛C题 二等奖 赛题论文
2018年中国研究生数学建模竞赛C题 对恐怖袭击事件记录数据的量化分析 恐怖袭击是指极端分子或组织人为制造的.针对但不仅限于平民及民用设施的.不符合国际道义的攻击行为,它不仅具有极大的杀伤性与破坏力, ...
- EOJ Monthly 2018.7 B.锐角三角形(数学几何+思维)
描述 是否存在面积为S/2的整点锐角三角形?存在输出Yes并输出三个整点坐标,否则输出No. 注意如果存在输出的坐标必须在long long范围内. Input 第一行一个整数S(1<=S< ...
- 2018 Arab Collegiate Programming Contest (ACPC 2018) H - Hawawshi Decryption 数学 + BSGS
H - Hawawshi Decryption 对于一个给定的生成数列 R[ 0 ] 已知, (R[ i - 1 ] * a + b) % p = R[ i ] (p 是 质数), 求最小的 x 使得 ...
- ccpc 2018 final G - Pastoral Life in Stardew Valley
#include <iostream> #include<cstdio> #include<cstring> #include<queue> using ...
- 2017年全国卷3的21题与2018年全国卷3的21题命题背景是同一个函数$y=\frac{2x}{\ln(x+1)}$(再次瞎谈)
2017年四川高考数学(全国卷3)理科21题第1问 已知函数\(f(x)=x-1-a\ln x\) (1)若\(f(x)\geqslant 0\),求\(a\)的值\(.\) 该不等式等价于$a\ln ...
- 求等差数列前$n$项和$S_n$的最值
一.方法依据: 已知数列\(\{a_n\}\)是等差数列,首项为\(a_1\),公差为\(d\),前\(n\)项和为\(S_n\),则求\(S_n\)的最值常用方法有两种: (1).函数法:由于\(S ...
- 用Python解方程
一元一次方程 例题1: 这是北师大版小学六年级上册课本95页的一道解方程练习题: 大家可以先口算一下,这道题里面的x的值为200 接下来我们用python来实现,代码如下,每一句代码后面都写有解释语: ...
- 2018 CCPC 吉林站 H Lovers
2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, ...
随机推荐
- 数据库lib7第2, 3题(创建索引和触发器)
2. 分别为上述建立的表格建立适当的索引,请描述建立索引的过程(可以截图或者写SQL).其中,要求对SPJ标中的SNo, PNo字段各建立一个索引,为(PNo, JNo)的组合建立一个索引.请问,SN ...
- 【JZOJ4745】【NOIP2016提高A组模拟9.3】看电影
题目描述 听说NOIP2016大家都考得不错,于是CCF奖励省常中了 K 张变形金刚5的电影票奖励OI队的同学去看电影.可是省常中OI队的同学们共有 N(N >= K)人.于是机智的你想到了一个 ...
- struts1之工作原理
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zkn_CS_DN_2013/article/details/34452341 1.初始化:strut ...
- javascript如何将时间戳转为24小时制
var now = new Date(parseInt(1446634507) * 1000);console.log(now.toLocaleString('chinese',{hour12:fal ...
- 2019-8-30-C#-从零开始写-SharpDx-应用-笔刷
title author date CreateTime categories C# 从零开始写 SharpDx 应用 笔刷 lindexi 2019-8-30 8:50:0 +0800 2019-6 ...
- Python2 生成器 简介
1. A generator: provide a kind of function that can return an intermediate result ("the next va ...
- RNN与 LSTM 网络
循环神经网络(RNN) 人们的每次思考并不都是从零开始的.比如说你在阅读这篇文章时,你基于对前面的文字的理解来理解你目前阅读到的文字,而不是每读到一个文字时,都抛弃掉前面的思考,从头开始.你的记忆是有 ...
- 【Leetcode堆和双端队列】滑动窗口最大值(239)
题目 给定一个数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧.你只可以看到在滑动窗口内的 k 个数字.滑动窗口每次只向右移动一位. 返回滑动窗口中的最大值. 示例: 输入 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第八章:光照
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第八章:光照 代码工程地址: https://github.com/j ...
- Docker初步了解 2016-10-30 20:46 279人阅读 评论(31) 收藏
什么是docker? Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器. Docker本质上是一种软件,让用户创建镜像(很像虚拟机的模板),并且随后在容器里 ...