*【CodeForces - 1088 ABC】套题比赛,A水题B模拟C构造D交互

A.

Input

The only line contains the integer xx (1≤x≤100)(1≤x≤100).

Output

You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).

Examples

Input

10

Output

6 3

Input

1

Output

-1

解题报告:

   就是给你一个x,让你构造一个a和b,满足和x的这仨关系就行了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;int main()
{int x,a,b;cin>>x;int flag = 0;for(int i = 1; i<=x; i++) {for(int j = i; j<=x; j+=i) {if(i*j>x && j/i < x) {flag = 1;a=j;b=i;break;}}if(flag) break;}if(flag) printf("%d %d\n",a,b);else puts("-1");return 0 ;}

 


B.

给你n个数的数组,给一个k。让你重复执行k次下列操作:每次选中序列中不为0的最小的数并输出,然后把序列中所有非零的数都减去这个选中的数。如果序列已经都是0了,那就输出0.

Examples

Input

3 5
1 2 3

Output

1
1
1
0
0

Input

4 2
10 3 5 3

Output

3
2

Note

In the first sample:

In the first step: the array is [1,2,3][1,2,3], so the minimum non-zero element is 1.

In the second step: the array is [0,1,2][0,1,2], so the minimum non-zero element is 1.

In the third step: the array is [0,0,1][0,0,1], so the minimum non-zero element is 1.

In the fourth and fifth step: the array is [0,0,0][0,0,0], so we printed 0.

In the second sample:

In the first step: the array is [10,3,5,3][10,3,5,3], so the minimum non-zero element is 3.

In the second step: the array is [7,0,2,0][7,0,2,0], so the minimum non-zero element is 2.

解题报告:

  先别看哪个Node,,有的时候会误导你的思路。。其实这题就是将减的数给可持久化一下、、因为你想啊你总不能减一个数,就将序列中的数都变化一下吧,,所以解决方法就是用一个sub来动态记录变化的数的值。为啥可以这样呢?因为你虽然要变化整个数组中的值,,但是其实你就算不变化,,也不会影响下次你取数组中的最小值(因为大家都减同一个数,相对的大小关系肯定没变啊)所以就用一个变量记录就行了。

AC代码1:(排序版)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll a[MAX];
int main() {int n,k;cin>>n>>k;for(int i=1; i<=n; i++) scanf("%lld",a+i);ll sub=0;sort(a+1,a+n+1);for(int i=1,j=1;j<=k;i++,j++) {if(i>n) {printf("0\n");} else {while(1) {if(a[i]!=sub) break;i++;if(i > n) {printf("0\n");break;}}if(i<=n) {a[i]-=sub;printf("%lld\n",a[i]);sub+=a[i];}}}return 0;
}

或者用优先队列也可以写:

AC代码2:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
priority_queue<int, vector<int>, greater<int> > pq;
int n,k;
int main() {cin>>n>>k;for(int i = 1,tmp; i <= n; i ++) {scanf("%d",&tmp);if(tmp) pq.push(tmp);}int sub = 0;while(k--) {if(!pq.empty()) {int cur = pq.top();while(cur - sub == 0 && !pq.empty()) {pq.pop();cur=pq.top();}printf("%d\n",cur-sub);sub += (cur-sub);}else puts("0");}return 0;
}

不过更适合我的方式其实是先判断一堆直到只能变成0。然后再看看剩余的次数是否大于0,如果大于0再输出k次的0就行了、

 


C.

不想写题意了。。**构造一眼题

You're given an array aa of length nn. You can perform the following operations on it:

  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.
  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.

Can you make the array strictly increasing in no more than n+1n+1 operations?

Input

The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.

The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.

Output

On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.

To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.

Examples

Input

3
1 2 3

Output

0

Input

3
7 6 3

Output

2
1 1 1
2 2 4

Note

In the first sample, the array is already increasing so we don't need any operations.

In the second sample:

In the first step: the array becomes [8,6,3][8,6,3].

In the second step: the array becomes [0,2,3][0,2,3].

好吧我还是写一下题意。。就是说给你n个数,给你两种操作:1.任取一个x,让区间内所有的数都加上这个x。2.任取一个x,让区间内所有的数都取模这个x。(其中x<=1e6)。使得这个序列变成一个严格递增序列,让你输出每次操作是什么,和怎么操作、、

解题报告:

   1分钟出标算,,10分钟WA两发,,刚开始这个大数去了1e7,,(没读题),,后来WA1,改成1e6,感觉该没问题了吧,WA2,,发现后面在取模的时候去的x会超过1e6,,再改成5e5,AC。。

其实这题上来就取个5000左右就行了啊。。

不难构造,,题意都提示的很明显了,,n+1次操作,那肯定猜一个n次一个1次呗,,然后不难想到加一个大数,然后每次都取模,让他构造成一个1~n的序列就完事了。

(白白丢掉100分啊,,,心疼)(另外,应该输出a[i]-i,,别写成了a[i]-1,,,)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll a[MAX];
int main()
{int n;cin>>n;for(int i = 1; i<=n; i++) scanf("%lld",a+i); printf("%d\n",n+1);printf("1 %d 500000\n",n);for(int i = 1; i<=n; i++) a[i] += 500000;for(int i = 1; i<=n; i++) {printf("2 %d %lld\n",i,a[i]-i);}return 0 ;}

D.

 未补。抽空学学交互题吧、、

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441067.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php 计算前几天,php计算几分钟前、几小时前、几天前的几个函数、类分享

搜索热词一、函数实现实例1&#xff1a;代码如下:function time_tran($the_time){$now_time date("Y-m-d H:i:s",time()8*60*60);$now_time strtotime($now_time);$show_time strtotime($the_time);$dur $now_time - $show_time;if($dur < 0){return $the_tim…

【CodeForces - 608D】Zuma(区间dp)

题干&#xff1a; Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Geno…

matlab没有int函数,matlab 未定义与 'char' 类型的输入参数相对应的函数 'int'。

最后你那zd句plot(int(k),double(s));里的int(k);不对。你如果想以k为横坐标&#xff0c;直接把int去掉&#xff0c;如回果非想要变成整数可以用floor(k);注&#xff1a;fix&#xff1a;向零取整 floor&#xff1a;向小取整 round&#xff1a;四舍五入 ceil&#xff1a;向...如…

【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)

题干&#xff1a; It is so boring in the summer holiday, isnt it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each …

java读取yaml配置文件,snakeyaml读取yaml配置文件

下面上我解析yaml文件的例子&#xff1a;// me.yamlage: 1name: jiaobuchongparams:event: whats upurl: http://www.jiaobuchong.comfavoriteBooks:- Gone with the wind- The Little Prince对应的JavaBean类&#xff1a;// Me.javapublic class Me {private Integer age;priv…

算法讲解 -- 区间dp经典模型与优化(石子归并)

石子合并问题是最经典的DP问题。首先它有如下3种题型&#xff1a; PPT讲解&#xff1a;点击打开链接 (1)有N堆石子&#xff0c;现要将石子有序的合并成一堆&#xff0c;规定如下&#xff1a;每次只能移动任意的2堆石子合并&#xff0c;合并花费为新合成的一堆石子的数量。求将…

cpu影响matlab仿真速度吗,Proteus仿真速度很慢的分析

类型&#xff1a;行业软件大小&#xff1a;1.1M语言&#xff1a;中文 评分&#xff1a;6.5标签&#xff1a;立即下载这篇文章是我的个人实践经验&#xff1a;很多朋友在做Proteus硬件仿真的时候可能都碰上了仿真速度慢的问题&#xff0c;在点击了开始仿真之后&#xff0c;CPU过…

【HDU - 5900】QSC and Master(区间dp)

题干&#xff1a; Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University&#xff0c;You are facing the main building of Northeastern University.Ninety-nine percent of the students have not …

php set_timeout,和 JS 一样的 php setTimeout 函数

112016-07-11 21:34:11 08:00szopen 貌似没有复杂啊//enable ticksdeclare (ticks 1);//setTimeout event list$timeoutQueue new SplObjectStorage;register_tick_function(function() {global $timeoutQueue;foreach ($timeoutQueue as $v) {$callBack $v();if (is_callab…

mysql 7天自动拒单功能,mysql查询最近7天的数据,没有数据自动补0

select DATE( createtime) date , createtime, count(1) as count from order表 where DATEDIFF( now(), createtime)<7group by date ;12 月九号没有;给他在关联一张日期的表;--生成从今天开始完整的7天日期DECLARE LastSevenDaytable(day date)DECLARE StartDaydate …

【UVA - 10038】Jolly Jumpers (模拟,水题,标记)

题干&#xff1a; 题目大意&#xff1a; 要任意相邻的两个数的绝对值在[1,n)&#xff0c;而且这个范围内的每个数都要出现一次。 解题报告&#xff1a; 直接模拟就行了、 AC代码&#xff1a; #include<cstdio> #include<iostream> #include<algorithm> …

基于维纳滤波的语音增强算法 matlab,基于维纳滤波语音增强算法的改进实现

通过对维纳滤波的介绍,实现了基本维纳滤波效果;利用两级维纳滤波和两级滤波器组滤波方法实现了语音增强,达到了良好的效果。维普资讯 http://doc.docsou.com文章编号&#xff1a;0 2 8 8 (o 7 0 - 0 4 0 10—6 4 2 o )1 0 4 - 3基于维纳滤波语音增强算法的改进实现白文雅&#…

【CodeForces - 245H 】Queries for Number of Palindromes (带容斥的区间dp)

题干&#xff1a; Youve got a string s  s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of …

php7 获取文件类型,太简单了!PHP获取文件扩展名的7中方法

PHP中获取文件扩展名的方法第一种&#xff1a;$file x.y.z.png;echo substr(strrchr($file, .), 1);解析&#xff1a;strrchr($file, .)strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置&#xff0c;并返回从该位置到字符串结尾的所有字符第二种&#xff1a;$file…

【EOJ Monthly 2018.12 - A,B,C】套题训练,部分题解

A. 题干&#xff1a; A. 仰望星空 单测试点时限: 2.0 秒 内存限制: 512 MB 你就这样静坐在草地上&#xff0c;离我稍远的地方。 我用眼角瞅着你&#xff0c;你什么话也别说。 语言是误会的根源。 但是&#xff0c;每天&#xff0c;你可以坐得离我近一些…… 你和她一起仰头…

php android 复制粘贴板,Android_Android剪贴板用法详解,本文实例详述了Android剪贴板的 - phpStudy...

Android剪贴板用法详解本文实例详述了Android剪贴板的用法&#xff0c;分享给大家供大家参考。具体方法分析如下&#xff1a;这里首先需要注意的一点&#xff0c;就是在使用Android剪贴板的时候大家只记住一点就行了&#xff0c;不管是安卓设备还是PC机&#xff0c;复制粘贴在同…

【Uva - 10047 】The Monocycle(搜索,bfs记录状态)

题干&#xff1a; Uva的题目就不粘贴题干了&#xff0c;&#xff0c;直接上题意吧。 有你一个独轮车&#xff0c;车轮有5种颜色&#xff0c;为了5中颜色的相对位置是确定的。有两种操作&#xff1a;1.滚动&#xff1a;轮子必须沿着顺时针方向滚动&#xff0c;每滚动一次会到达…

matlab中bwlabel意思,Matlab 里bwlabel 函数的具体含义

Matlab函数bwlabel&#xff1a;在二值图像中标记连通区域用法&#xff1a;L bwlabel(BW,n)返回一个和BW大小相同的L矩阵&#xff0c;包含了标记了BW中每个连通区域的类别标签&#xff0c;这些标签的值为1、2、num(连通区域的个数)。n的值为4或8&#xff0c;表示是按4连通寻找区…

php百度搜索框代码,基于jquery的仿百度搜索框效果代码_jquery

先看看整个的效果图&#xff1a;图一&#xff1a;图二&#xff1a;图三&#xff1a;图四&#xff1a;大概的效果图就这样&#xff0c;接下来直接看源码页面&#xff1a;CSS&#xff1a;.autoSearchText{border:solid 1px #CFCFCF;height:20px;color:Gray;}.menu_v{margin:0;pad…

【UVA - 227】Puzzle (模拟,水题)

题干&#xff1a; Puzzle A childrens puzzle that was popular 30 years ago consisted of a 5x5 frame which contained 24 small squares of equal size. A unique letter of the alphabet was printed on each small square. Since there were only 24 squares within the…