sum

Accepts: 640
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

题意:求字符串中是否存在连续子串和为m的倍数,是则输出"YES“,否则输出”NO“

分析:
维护前缀和,当时没想到,太弱,如果当前模得到0或者两个莫数据相同则YES,否则NO,可以用抽屉原理,(N>=M)->YES

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring> using namespace std;
const int maxn = 1e5+; bool used[maxn]; int main()
{
int n, m;
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
memset(used, , sizeof(used));
used[] = true;
int sum = ,x;
bool flag = false;
if(n>=m)
{
flag=;
for(int i=;i<n;i++) scanf("%d",&x);
}
else
{
for(int i = ; i < n; ++ i)
{
scanf("%d", &x);
sum += x;
sum %= m;
if(used[sum]) {
flag=true;
}
else used[sum] = true;
}
}
printf("%s\n", flag ? "YES" : "NO");
}
return ;
}
/*
2
3 3
3 1 1
3 7
6 6 9
*/

domino

Accepts: 462
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次机会,n张扑克牌,问全部推倒扑克牌,扑克牌的最小高度。

分析:
贪心排序,找到前n-k个数相加即可。(详情见bc的题解)

//贪心,将位置距离重排,取前n-k个,奥妙重重
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
int t,k,n,a[];LL sum;
int main()
{
for(scanf("%d",&t);t--;)
{
scanf("%d%d",&n,&k);
for(int i=;i<n-;i++) scanf("%d",a+i);
if(n<=k) printf("%d\n",n);
else
{
sort(a,a+n-);sum=n;
for(int i=;i<n-k;i++) sum+=a[i];
printf("%I64d\n",sum);
}
}
}

abs

Accepts: 136
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

题意:
给出一个数,找到距离该数最小的数(满足题目要求)。

分析:
明显要对x开方,然后枚举35000以内的素数,如果能够连除某个素数两次及以上,则重新进入循环,否则输出,记住是对开根号后的x加减,int乘以int要加LL,应对爆int的情况出现

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std; #define LL long long
#define F(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define rep(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)
#define rek(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b)) const int P=sqrt(1e9);
int prime[P];
bool is_prm[P+]; bool check(LL x){
for(int i=;i<=prime[]&&prime[i]*prime[i]<=x;++i)
if(x%prime[i]==&&(x/=prime[i])%prime[i]==)
return ;
return ;
}
inline LL ab(LL x)
{
return x<?-x:x;
}
int t;
LL x;
const int eps=1e-;
int main()
{
//欧拉筛
for(int i=;i<=P;++i){
if(!is_prm[i])prime[++prime[]]=i;
for(int j=;j<=prime[]&&i*prime[j]<=P;++j){
is_prm[i*prime[j]]=;
if(i%prime[j]==)break;
}
} //freopen("in.txt","r",stdin);
for(scanf("%d",&t);t--;)
{
scanf("%I64d",&x);
for(int yy1=sqrt(x),yy2=yy1+;;)
{
//printf("%lf\n",sqrt(x));
//printf("yy1=%I64d y1=%I64d\n",yy1,y1);
//printf("%I64d\n",yy1);
if(yy1>&&(x-(LL)yy1*yy1<(LL)yy2*yy2-x))
{
if(!check(yy1)) goto f;else {
printf("%I64d\n",(x-(LL)yy1*yy1));goto flag;
}
f:yy1--;
}
///yy2=(LL)sqrt(y2);//printf("yy2=%I64d y2=%I64d\n",yy2,y2);
else
{
if(!check(yy2)) goto g;else {
printf("%I64d\n",((LL)yy2*yy2-x));goto flag;
}
g:yy2++;
}
}
flag:;
}
return ;
}

BestCoder Round #85的更多相关文章

  1. BestCoder Round #85(ZOJ1569尚未验证)

    A题 子序列和啊,就要想到前缀和的差.这个转换一定要!记着!那么i到j的一段子序列和Sij%m ==  0就等价于(Sj-Si-1)%m == 0 了,那么什么意思呢?就是如果有两段前缀和%m的模是一 ...

  2. BestCoder Round #85 hdu5778 abs(素数筛+暴力)

    abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...

  3. BestCoder Round #85 hdu5777 domino

    domino 题意: 问题描述 小白在玩一个游戏.桌子上有n张多米诺骨牌排成一列.它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒.每个骨 牌倒下的时候,若碰到了未倒下的骨牌,可以把它推倒 ...

  4. BestCoder Round #85 hdu5776 sum

    sum 题意: 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出NO 输入描述 输入文件的第一行有一个正整数T,表示数据组数. 接下去有T组数据,每组数据的第一行有两个 ...

  5. HDU5780 gcd (BestCoder Round #85 E) 欧拉函数预处理——分块优化

    分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后 ...

  6. HDU5779 Tower Defence (BestCoder Round #85 D) 计数dp

    分析(官方题解): 一点感想:(这个题是看题解并不是特别会转移,当然写完之后看起来题解说得很清晰,主要是人太弱 这个题是参考faebdc神的代码写的,说句题外话,很荣幸高中和faebdc巨一个省,虽然 ...

  7. HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力

    分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...

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

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

  9. HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题

    分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...

随机推荐

  1. YASKAWA电机控制(2)---调试

    2015 5 23 基础调试—点动 上次接线由于没有接地,导致外壳带电,非常危险. 由于上次接线端子被弄坏,这次自己重做.由于没有压线钳,只用尖嘴钳把线压近端子,有可能会松动. 接线的时候Lc1.Lc ...

  2. JS代码片段:判断一个元素是否进入可视区域

    // Determine if an element is in the visible viewport function isInViewport(element) { var rect = el ...

  3. Segmentation Fault错误原因总结

    最近在项目上遇到了Segmentation Fault的错误,一直调试不出来是哪里出了问题,对于刚接触嵌入式的,也不知道该如何去调试一个项目,定位内存问题,纠结了好几天,好阿红整理下自己的思路.从头开 ...

  4. Linux3.4内核的基本配置和编译

    转载自:http://www.embedu.org/Column/Column634.htm 作者:李昕,华清远见研发中心讲师. 了解Linux3.4内核的特性及新增功能,掌握Linux内核的编译过程 ...

  5. c# webbrowser 随机点击链接 2

    找到广告代码所在的div或table ,然后用WebBrowser执行js去点这个div(或table) 那个广告是js实现的,你浏览的时候是看不到图片和连接的,请问各位大虾应该怎么实现?给点思路.. ...

  6. java中的clone

    .clone 要实现cloneable接口: .深度clone和浅度clone .对象.clone() 1. Clone&Copy      假设现在有一个Employee对象,Employe ...

  7. 待实践三:MVC3下 路由的测试 使用 RouteDebug.dll 来测试判断路由是否符合

    在需要进行测试路由是否匹配的项目中引用    RouteDebug.dll   并且在MVC的Global.asax里面加入一段代码   //下面这行代码一定是在 RegisterRoutes(Rou ...

  8. 如何解决重启数据库时报ORA-01031无法登数据库

    问题现象:以无用户方式登录数据库,重启或关闭数据时,遇到下列问题: C:\Documents and Settings\xuzhengzhu>sqlplus /nolog SQL*Plus: R ...

  9. C# new用法总结

    有一道这样的题:写出c#中new关键字的三种用法,思前想后挖空心思也只想出了两种用法,回来查了下msdn,还真是有第三种用法: 用于在泛型声明中约束可能用作类型参数的参数的类型,这是在Framewor ...

  10. 反转链表 --剑指offer

    题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反正后链表的头结点. #include<stdio.h> #include<malloc.h> typedef str ...