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, ...
随机推荐
- Hdu 4143
题目链接 好久没有在Hdu水题了,于是乎在无聊之际还是找了一道水题, 但是看完题目之后,明显是个数学题,我还是感觉有点打触的. 因为一直对数学题没有多大信心. 分析了一下,Y^2 = X^2 + n ...
- vagrant up 时提示错误 cound not open file
根据教程:https://laravel-china.org/docs/laravel-development-environment/5.5/development-environment-wind ...
- 封装函数通过输入(元素,属性,目标值)改变div样式
## 假设一个div样式如下```html<!DOCTYPE html><html lang="en"> <head> <meta cha ...
- poj2449第K短路问题(A*算法)
启发函数:f(x)=g(x)+h(x); g(x)表示初始点到x状态的代价,h(x)表示从x的状态到目标状态的代价的估计值(并不是真实的),实际最小代价<=h(x); 起点s,终点t,x.v=s ...
- kendo grid 使用小结
需要注意的: 1. id,如果没有指定id则会导致create.update等操作无法正常使用. 头疼事项: 1. 服务端失败返回error数据.如果是编辑状态,还不能友好提示错误.当然可以使用大量代 ...
- 微信开发之web开发者工具
web开发者工具. 有任何疑问或建议请私信我,或者在评论区大家一起探讨. 概述 为帮助开发者更方便.更安全地开发和调试基于微信的网页,我们推出了 web 开发者工具.它是一个桌面应用,通过模拟微信客户 ...
- 使用 git 来管理 PCB 版本
使用 git 来管理 PCB 版本 在传统的 PCB 版本管理是复制一份,再重命名,写上日期,写上修改日志. 自从接触了 git 后,发现 git 的版本管理完全可以胜任,且可以做的更好. 原来使用商 ...
- jq 操作CSS
方式有两种,一种是操作元素className间接控制样式,一种是设置css属性值直接控制样式. jQuery 属性操作方法.jQuery CSS 操作函数 1.addClass() $(selecto ...
- php json_encode输出为空问题
这种情况一般是json_encode序列化数组时出现错误,错误原因有很多,可以通过json_last_error函数来查看错误原因!!! 可能的原因 ------------------------- ...
- SDUT-2124_基于邻接矩阵的广度优先搜索遍历
数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一个无向连通图 ...