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, ...
随机推荐
- Spark day06
SparkStreaming简介 SparkStreaming是流式处理框架,是Spark API的扩展,支持可扩展.高吞吐量.容错的实时数据流处理,实时数据的来源可以是:Kafka, Flume, ...
- scala2.11读取文件
1.读取行 要读取文件的所有行,可以调用scala.io.Source对象的getLines方法: import scala.io.Source val source = Source.fromFil ...
- AtCoder Beginner Contest 084 C - Special Trains
Special Trains Problem Statement A railroad running from west to east in Atcoder Kingdom is now comp ...
- hdu3472 混合图判断欧拉通路
对于欧拉回路,先判断出度入度的差是否为偶数,然后最大流一次. 此题是判断有无欧拉通路,前提要判断图是否连通,然后欧拉通路的条件:要么出入度差没有奇数,或者只有2个点. 所以先统计差为奇数的个数,如果不 ...
- 谷歌好样的,把 www 也干掉了
谷歌好样的,把 www 也干掉了 继把 http 干掉后,这次 Chrome 76 连 https 和 www 都一起干掉了. 喜欢简洁,但这个功能演化过程可不简单. 最早觉得把 http 干掉很不方 ...
- 2016 Asia Jakarta Regional Contest A - Confusing Date Format UVALive 7711 【模拟题】
A - Confusing Date Format 题目大意:就是有六种日期格式,给你一个字符串,判断它能组成多少种可能的日期. 第一次WA是:1.没有判重,2.没有特判题目要求的数据,3.判断天数时 ...
- JSTL的时间格式化
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 开头第一句必须上 ...
- Vue组件跨层级通信
正常组件间通信 父->子组件 是通过属性传递 子->父组件 是通过this.$emit()传递 this.$emit()返回的是this,如果需要一些值 可使用callback方式传递 p ...
- myeclipse2013在线安装svn
之前安装svn一直不行.弄了好久.还是在线安装方便. 在Help里面点击Install from Site,然后直接图解: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...
- WPF Canvas实现进度条
原文:WPF Canvas实现进度条 先看效果图: 思路: 一个Canvas做背景,一个Canvas用来显示进度,图片放在显示进度的Canvas中,靠右设置为图片本身宽度一半的距离,视觉上实现以图片中 ...