A---Ehab and another constriction problem

https://codeforc.es/contest/1088/problem/A

题意:给定一个数$x$找两个在$1$~$x$之间的数$a$和$b$,$b$是$a$的因子,$a*b > x, \frac{a}_{b} < x$

思路:两个数都选$x$自己就可以了。在$x=1$的时候因为要求中不包含等号,所以是找不到这样的数的。

 #include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
//#include<cstdlib>
//#include<cstring>
//#include<algorithm>
//#include<queue>
//#include<vector>
//#include<set>
//#include<climits>
//#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define pi 3.1415926535
#define inf 0x3f3f3f3f int x; int main()
{
while(scanf("%d", &x)!= EOF){ if(x == ){
printf("-1\n");
}
else{
printf("%d %d\n", x, x);
} }
return ;
}

B---Ehab and substraction

https://codeforc.es/contest/1088/problem/B

题意:给定一个序列,每次找到非零的最小值,让剩下的所有非零的数减去他。输出$k$次操作每次选择的这个数。

思路:用一个优先队列维护一下就可以了。然后用一个变量记录总的减掉的总值。

 #include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
//#include<cstdlib>
//#include<cstring>
#include<algorithm>
#include<queue>
//#include<vector>
//#include<set>
//#include<climits>
//#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define pi 3.1415926535
#define inf 0x3f3f3f3f int n, k;
const int maxn = 1e5 + ;
int num[maxn]; int main()
{
while(scanf("%d%d", &n, &k) != EOF){
priority_queue<int, vector<int>, greater<int> >que;
int mx = -;
for(int i = ; i < n; i++){
scanf("%d", &num[i]);
mx = max(mx, num[i]);
que.push(num[i]);
} LL sub = ;
for(int i = ; i < k; i++){
if(que.empty())printf("0\n");
else{
int now = que.top();
que.pop();
now -= sub;
while(!now && !que.empty()){
now = que.top();
que.pop();
now -= sub;
}
printf("%d\n", now);
sub += (LL)now;
}
}
}
return ;
}

C---Ehab and a 2-operation task【思维好题】

https://codeforc.es/contest/1088/problem/C

题意:

给定一个序列

操作1,选定一个下标$i$,和一个数$x$,对$1$~$i$的每一个数都加上$x$

操作2,选定一个下标$i$,和一个数$x$, 对$1$~$i$的每一个数都取模$x$

最多执行n+1次操作,使得最后的序列是递增的

思路:

用到了一些取模的性质,不太熟所以没想到。

如果有$a<b$,那么$a % b = a$

如果有$a > b > a /2$,那么有$a % b = a - b$

现在要让他是递增的序列,只需要让第$i$个数是$i$就可以了。假设第$i$数是$num[i]$,只需要执行$num[i] % (num[i] - i)$

所以首先给每一个数加上一个很大的数,比如$1e5 + 5$

然后从前往后对他们取模,连负数都不需要考虑。

 #include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
//#include<cstdlib>
//#include<cstring>
#include<algorithm>
#include<queue>
//#include<vector>
//#include<set>
//#include<climits>
//#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define pi 3.1415926535
#define inf 0x3f3f3f3f int n;
const int maxn = ;
const int add = 1e5 + ;
LL num[maxn]; int main()
{
while(scanf("%d", &n) != EOF){
for(int i = ; i < n; i++){
scanf("%lld", &num[i]);
num[i] += add;
} LL sub = ;
printf("%d\n", n + );
printf("1 %d %d\n", n, add);
for(int i = ; i < n; i++){
printf("2 %d %lld\n", i + , num[i] - i);
}
}
return ;
}

codeforces#525 Div2---ABC的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces 1323 div2题解ABC

    A. Even Subset Sum Problem 签到题 #include <bits/stdc++.h> using namespace std; template <type ...

  8. codeforces#510 Div2

    pre过了三题 后来A题被hack了 B题终测挂了 两题其实都是有一个小细节没有处理好 中间C还因为cinT了一次 唉本来打的还不错的 还是太菜了 继续加油吧 A-Benches 有n张椅子 原来第i ...

  9. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  10. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. EF+LINQ事物处理

    在使用EF的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作同一条数据的同一个字段的话, ...

  2. 1.揭开消息中间件RabbitMQ的神秘面纱

    当你看到这篇博文的时候,相信你至少已经知道RabbitMQ 是一个非常优秀的消息中间件,它使用专门处理高并发的Erlang 语言编写而成的消息中间件产品. 当然如果你不知道也没关系,读完本篇你将Get ...

  3. 全面理解Javascript闭包和闭包的几种写法及用途【转】

    一.什么是闭包和闭包的几种写法和用法 1.什么是闭包 闭包,官方对闭包的解释是:一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.闭包的特点: 1. ...

  4. ES6,Array.of()函数的用法

    ES6为Array增加了of函数用已一种明确的含义将一个或多个值转换成数组. 因为,用new Array()构造数组的时候,是有二意性的. 构造时,传一个参数,表示生成多大的数组. 构造时,传多个参数 ...

  5. (4) MySQL中EXPLAIN执行计划分析

    一. 执行计划能告诉我们什么? SQL如何使用索引 联接查询的执行顺序 查询扫描的数据函数 二. 执行计划中的内容 SQL执行计划的输出可能为多行,每一行代表对一个数据库对象的操作 1. ID列 ID ...

  6. js计算字符串的字节数和字符串与二进制的相互转化

    一.js计算字符串的字节数方法: //blob获取字符串的字节 var debug = "好的"; var blob = new Blob([debug],{type : 'tex ...

  7. cp显示进度条

    cp显示进度条 alias cp='rsync -av --progress'

  8. 关于tomcat的session问题

    因为有需要每一个项目有独立端口,并且能够单独启动和关闭,所以在一台服务器上配置了多个tomcat.tomcat是完全一样的,只是各自的端口不一致. 现在的问题是单独启动一个tomcat完全没有问题. ...

  9. QT 中Widgets-Scene3d例子学习

    QT中自带的例子widgets-scene3d实现在基于Widget的应用程序中使用qml 3d场景的功能,我在此基础上,将basicshapes-cpp的例子加以嵌入: 相关代码如下:  C++ C ...

  10. linux环境下,对于一个大文件,如何查看其中某行的内容

    需求说明: 今天在做mysql数据导入的过程中,导入到最后有一个报错,报某张表不存在.然后就想看看这行到底是在做什么操作的时候报的错误. 报错信息: [mysql@host---- ~]$ cat n ...