[CodeChef-LTIME36]Akhil Recovers The Lost Array
来源:互联网 发布:tensorflow 谷歌 编辑:程序博客网 时间:2024/06/06 11:44
题目大意
给定
有
题目分析
大家喜闻乐见的数论构造题。
如果单纯地模拟题意,是想不到什么好的解法的。因为这样没用充分利用题目给的
既然是对连续子序列和的限制,很容易想到用前缀和来差分一下。设
首先显然有
注意前缀和包括位置
然后显然奇数前缀和与偶数前缀和差分才能得到奇数连续子序列,那么就有
那么我们枚举其中一个,就可以利用条件
显然直接在位置
时间复杂度
代码实现
第一次在CC上交题,Submit按钮找了半天。
#include <iostream>#include <cstdio>#include <cctype>using namespace std;typedef long long LL;int read(){ int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*f;}const int N=1000050;int T,n,E,O;LL e,o;int main(){ freopen("alost.in","r",stdin),freopen("alost.out","w",stdout); T=read(); while (T--) { n=read(); scanf("%lld %lld",&e,&o); for (E=1;E<=n+1;E++) { O=n+1-E; if (1ll*E*O==o) break; } if (1ll*E*O!=o) { printf("-1\n"); continue; } for (int i=1;i<E;i++) printf("2 "); if (E<=n) printf("3 "); for (int i=E+1;i<=n;i++) printf("2 "); printf("\n"); } fclose(stdin),fclose(stdout); return 0;}
0 0
- [CodeChef-LTIME36]Akhil Recovers The Lost Array
- codechef The Army
- Codechef Reach The Point
- (codechef)The Next Palindrome
- CODECHEF Fill The Matrix
- pku2057 The Lost House
- Lost in the City
- Lost in the City
- codechef The Lead Game 题解
- codechef The Morning Commute 题解
- codechef Closing the Tweets 题解
- 【CodeChef】Holes in the text
- 【Codechef】Tiptoe through the tulips
- 【CodeChef】 Queries on the String
- CodeChef Protecting The Poison【贪心】
- CodeChef PROTEPOI Protecting The Poison
- codechef Chef and Rainbow Array - 2
- [DP] Codechef .Chef And Fibonacci Array
- 五 skylable客户端操作
- nginx配置引发的403问题
- java中使用sax解析xml,以实体类集合的方式接受xml解析的值
- ios打包ipa的四种实用方法(.app转.ipa)
- MFC学习笔记——CDialog(为控件添加消息处理函数)
- [CodeChef-LTIME36]Akhil Recovers The Lost Array
- 悲观锁和乐观锁
- vim与复制,删除,粘贴,块操作以及快速替换功能
- 【腾讯Bugly干货分享】浅谈Android自定义锁屏页的发车姿势
- Block循环引用问题
- [poj 1961]Period[kmp]
- Android绘图——圆圈+水波
- Git新手必备命令整理
- idea编译器