sum

Accepts: 822
Submissions: 1744
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO

Input

The first line of the input has an integer T (1≤T≤101 \leq T \leq 101≤T≤10), which represents the number of test cases. For each test case, there are two lines: 1.The first line contains two positive integers n, m (1≤n≤1000001 \leq n \leq 1000001≤n≤100000, 1≤m≤50001 \leq m \leq 50001≤m≤5000). 2.The second line contains n positive integers x (1≤x≤1001 \leq x \leq 1001≤x≤100) according to the sequence.

Output

Output T lines, each line print a YES or NO.

Sample Input
2
3 3
1 2 3
5 7
6 6 6 6 6
Sample Output
YES
NO
 
第一题:同余,因为要求的是 (sum[i]-sum[j])%m == 0 ,所以 sum[i]%m = sum[j]%m ,所以判断一下所有的前缀和里面是否有余数相同的两个就好了,还要判一下sum[i]%m==0也是可行的.
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = ;
int sum[N];
bool vis[];
int main()
{
int tcase,n,m,x;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&n,&m);
sum[] = ;
bool flag = false;
memset(vis,false,sizeof(vis));
for(int i = ;i<=n;i++){
scanf("%d",&x);
sum[i] = sum[i-]+x;
if(sum[i]%m==) flag = true;
if(vis[sum[i]%m]) flag = true;
vis[sum[i]%m] = true;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}

domino

Accepts: 614
Submissions: 1498
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Little White plays a game.There are n pieces of dominoes on the table in a row. He can choose a domino which hasn't fall down for at most k times, let it fall to the left or right. When a domino is toppled, it will knock down the erect domino. On the assumption that all of the tiles are fallen in the end, he can set the height of all dominoes, but he wants to minimize the sum of all dominoes height. The height of every domino is an integer and at least 1.

Input

The first line of input is an integer T ( 1≤T≤101 \leq T \leq 10 1≤T≤10) There are two lines of each test case. The first line has two integer n and k, respectively domino number and the number of opportunities.( 2≤k,n≤1000002\leq k, n \leq 100000 2≤k,n≤100000) The second line has n - 1 integers, the distance of adjacent domino d, 1≤d≤1000001 \leq d \leq 100000 1≤d≤100000

Output

For each testcase, output of a line, the smallest sum of all dominoes height

Sample Input
1
4 2
2 3 4
Sample Output
9
 
题解:贪心,取前K大的距离减掉,其余的化为距离+1,最后一块为1,单独处理 k>=n的情况
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
int a[N];
int cmp(int a,int b){
return a>b;
}
int main(){
int tcase,n,k;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&n,&k);
long long sum = ;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
sum=sum+a[i]+;
}
if(n<=k){
printf("%d\n",n);
continue;
}
sort(a+,a+n,cmp);
for(int i=;i<k;i++){
sum-=a[i];
}
printf("%I64d\n",sum+);
}
return ;
}

abs

Accepts: 241
Submissions: 927
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Given a number x, ask positive integer y≥2y\geq 2y≥2, that satisfy the following conditions:

  1. The absolute value of y - x is minimal
  2. To prime factors decomposition of Y, every element factor appears two times exactly.
Input

The first line of input is an integer T ( 1≤T≤501\leq T \leq50 1≤T≤50) For each test case,the single line contains, an integer x ( 1≤x≤10181\leq x \leq {10} ^ {18} 1≤x≤10​18​​)

Output

For each testcase print the absolute value of y - x

Sample Input
5
1112
4290
8716
9957
9095
Sample Output
23
65
67
244
70 题解:分别往左找往右找,如果这个数分解的质因数个数都只有1,那么他本身的平方每个质因数个数就为2了,往右的时候(k+i)*(k+i)>=n这个条件一定要记得写。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const LL INF = (LL)(((LL))<<-);
bool can(LL num)
{
for(int i=; i*i<=num; i++)
{
int cnt = ;
if(num%i==)
{
while(num%i==)
{
num/=i;
cnt++;
if(cnt>) return false;
}
}
}
return true;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{ LL n;
scanf("%I64d",&n);
if(n<=){
printf("%I64d\n",-n);
continue;
}
LL k = sqrt(n);
LL ans = INF;
for(int i=;; i++)
{
if((k+i)*(k+i)>=n&&can(k+i))
{
ans = min(ans,abs((k+i)*(k+i)-n));
break;
}
}
for(int i=;; i++)
{
if(can(k-i)&&(k-i)>=)
{
ans = min(ans,abs((k-i)*(k-i)-n));
break;
}
}
printf("%I64d\n",ans);
}
return ;
}

BestCoder Round #85 前三题题解的更多相关文章

  1. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  2. BestCoder Round #86 二,三题题解(尺取法)

    第一题太水,跳过了. NanoApe Loves Sequence题目描述:退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列.他在纸上随便写了一个长度为 nn ...

  3. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  4. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  5. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  6. Codeforces Round #530 (Div. 2) (前三题题解)

    总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...

  7. HDU5777 domino (BestCoder Round #85 B) 思路题+排序

    分析:最终的结果肯定会分成若干个区间独立,这些若干个区间肯定是独立的(而且肯定是一边倒,左右都一样) 这样想的话,就是如何把这n-1个值分成 k份,使得和最小,那么就是简单的排序,去掉前k大的(注意l ...

  8. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

随机推荐

  1. hdu 5620

    KK's Steel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. POJ1236:Network of Schools (思维+Tarjan缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24880   Accepted: 99 ...

  3. Kafka消息delivery可靠性保证(Message Delivery Semantics)

    原文见:http://kafka.apache.org/documentation.html#semantics kafka在生产者和消费者之间的传输是如何保证的,我们可以知道有这么几种可能提供的de ...

  4. generatorConfiguration配置文件及其详细解读

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  5. uva 1506 Largest Rectangle in a Histogram

    Largest Rectangle in a Histogram http://acm.hdu.edu.cn/showproblem.php?pid=1506 Time Limit: 2000/100 ...

  6. LightOJ 1306 - Solutions to an Equation 裸EXGCD

    本题是极其裸的EXGCD AX+BY+C=0 给你a b c 和x与y的区间范围,问你整数解有几组 作为EXGCD入门,题目比较简单 主要需要考虑区间范围的向上.向下取整,及正负符号的问题 问题是这正 ...

  7. Bzoj4710 [Jsoi2011]分特产

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 96  Solved: 62[Submit][Status][Discuss] Description ...

  8. 51nod 1190 最小公倍数之和 V2

    给出2个数a, b,求LCM(a,b) + LCM(a+1,b) + .. + LCM(b,b). 例如:a = 1, b = 6,1,2,3,4,5,6 同6的最小公倍数分别为6,6,6,12,30 ...

  9. 【51NOD】数据流中的算法

    [算法]数学 [题解] 1.平均数:累加前缀和.//听说要向下取整? 2.中位数:双堆法,大于中位数存入小顶堆,小于中位数存入大顶堆,保证小顶堆内数字数量≥大顶堆,奇数则取小堆顶,偶数则取两堆顶/2. ...

  10. 【BZOJ】1486 [HNOI2009]最小圈

    [算法]二分+spfa [题解]据说这个叫分数规划? 0-1分数规划 二分答案a,则对于任意的环有w/k≤a即w-ak≤0,若满足条件则a变小,否则a变大. 因为w=w1+w2+...+wk,所以变形 ...