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, ...
随机推荐
- Thrift源码分析(一)-- 基本概念
我所在的公司使用Thrift作为基础通信组件,相当一部分的RPC服务基于Thrift框架.公司的日UV在千万级别,Thrift很好地支持了高并发访问,并且Thrift相对简单地编程模型也提高了服务地开 ...
- poj2125 最小点权覆盖集
题意:有一张图,对于每个点,有出边和入边,现在目的是删除改图的所有边,对于每个点,删除出边的花费Wi-,删除入边的花费Wi+,现在的目的求删去所有边后的花费最小. 建图方法:对于每个点i,拆点为i,i ...
- IDEA:将WEB-INF\lib下的Jar包添加到项目中
打开Project Structure[可以使用快捷键:Ctrl+Alt+Shift+S] 左侧选中Modules,在Dependecies中,点击右侧"+"号,选择JARS or ...
- oralce Sysdba和sysoper的区别
Sysdba是一个允许读者执行任何数据库任务的全能特权.Sysoper是一个威力次之的特权,它赋予了启动和关闭能力,但限制其他管理性任务
- oracle编写分页过程
有了上面的基础,相信大家可以完成分页存储过程了,要求,请大家编写一个存储过程,要求可以输入表名.每页显示记录数.当前页.排序字段(deptno降序).返回总记录数,总页数和返回结果集. 把一个字符串, ...
- 【转载】获取更多/proc/fd中有关socket的信息
Q: Looking in /proc/$mypid/fd/, I see these files lrwx------ cm_user cm_user Oct : -> /dev/pts/ ( ...
- bzoj2752 高速公路
列式子: 如果把从i号收费站到i+1号收费站之间路段编号设为i. 假如查询l号收费站到r号收费站之间的期望值. $ Ans_{l,r} = \sum\limits_{i=l}^{r-1} v_i ...
- 杨柳目-杨柳科-Info-新闻:“北京三害”之一,危害堪比雾霾和沙尘,杨絮为什么会肆虐
ylbtech-杨柳目-杨柳科-Info-新闻:“北京三害”之一,危害堪比雾霾和沙尘,杨絮为什么会肆虐 1.返回顶部 1. “北京三害”之一,危害堪比雾霾和沙尘,杨絮为什么会肆虐 18-05-0817 ...
- 惊闻!SOIC 和 SOP 竟然是有区别的
目录 惊闻!SOIC 和 SOP 竟然是有区别的 原因 对比 结论 惊闻!SOIC 和 SOP 竟然是有区别的 原因 一直以为 SOIC 和 SOP 是一样的,只是叫法不同. 对比 今天仔细查了才发现 ...
- 冒泡排序 Day07
package com.sxt.arraytest2; /* * 冒泡排序 * 思想:两两交换 一路大的向右 */ import java.util.Arrays; public class Bubb ...