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. get Status canceled 请求被取消

    1.chrome浏览器下状况: 2.环境: 一个页面A下 包含一个 iframe ,在子页面中用js点击A页面下的链接替换iframe内容脚本如下: window.parent.document.ge ...

  2. P25、面试题1:赋值运算符函数

    题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStr ...

  3. openfire的smack和asmack

    smack你可以看成是一套封装好了的用于实现XMPP协议传输的API,它是一个非常简单并且功能强大的类库,给用户发送消息只需要三行代码.下载地址:http://www.igniterealtime.o ...

  4. oracle SQL Develop导出数据库中的表格数据到excel

    首先打开oracle数据库 1.查询数据库, SELECT * FROM pub_attribute WHERE ELEMENT_CODE='bb382e10d7ce437b8a8c980ba20ac ...

  5. C#编写媒体播放器--Microsoft的Directx提供的DirectShow组件,该组件的程序集QuartzTypeLib.dll.

    使用C#编写媒体播放器时,需要用到Microsoft的Directx提供的DirectShow组件.用该组件前需要先注册程序集QuartzTypeLib.dll. 1.用QuartzTypeLib.d ...

  6. tahoma字体对中文字的影响

    一提到tahoma字体大家都会想到,它是一个英文字体,对中文不会有影响. 但是今天就遇到一个问题,tahoma字体会影响中文字的显示,如: html代码: <div class="bo ...

  7. 函数mem_pool_fill_free_list

    /********************************************************************//** Fills the specified free l ...

  8. asp.net 使用JQuery 调用Ashx 后面直接写方法名,通过反射找到对应的方法

    using System.Reflection; public class Industry_Manager : IHttpHandler { HttpRequest gRequest = null; ...

  9. codevs 1135 选择客栈

    这题没什么话说. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  10. Android Dialog使用举例

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...