BestCoder Round #85
sum
Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO
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 T lines, each line print a YES or NO.
2
3 3
1 2 3
5 7
6 6 6 6 6
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
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.
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
For each testcase, output of a line, the smallest sum of all dominoes height
1
4 2
2 3 4
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
Given a number x, ask positive integer y≥2y\geq 2y≥2, that satisfy the following conditions:
- The absolute value of y - x is minimal
- To prime factors decomposition of Y, every element factor appears two times exactly.
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≤1018)
For each testcase print the absolute value of y - x
5
1112
4290
8716
9957
9095
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的更多相关文章
- BestCoder Round #85(ZOJ1569尚未验证)
A题 子序列和啊,就要想到前缀和的差.这个转换一定要!记着!那么i到j的一段子序列和Sij%m == 0就等价于(Sj-Si-1)%m == 0 了,那么什么意思呢?就是如果有两段前缀和%m的模是一 ...
- BestCoder Round #85 hdu5778 abs(素数筛+暴力)
abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...
- BestCoder Round #85 hdu5777 domino
domino 题意: 问题描述 小白在玩一个游戏.桌子上有n张多米诺骨牌排成一列.它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒.每个骨 牌倒下的时候,若碰到了未倒下的骨牌,可以把它推倒 ...
- BestCoder Round #85 hdu5776 sum
sum 题意: 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出NO 输入描述 输入文件的第一行有一个正整数T,表示数据组数. 接下去有T组数据,每组数据的第一行有两个 ...
- HDU5780 gcd (BestCoder Round #85 E) 欧拉函数预处理——分块优化
分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后 ...
- HDU5779 Tower Defence (BestCoder Round #85 D) 计数dp
分析(官方题解): 一点感想:(这个题是看题解并不是特别会转移,当然写完之后看起来题解说得很清晰,主要是人太弱 这个题是参考faebdc神的代码写的,说句题外话,很荣幸高中和faebdc巨一个省,虽然 ...
- HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力
分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...
- HDU5777 domino (BestCoder Round #85 B) 思路题+排序
分析:最终的结果肯定会分成若干个区间独立,这些若干个区间肯定是独立的(而且肯定是一边倒,左右都一样) 这样想的话,就是如何把这n-1个值分成 k份,使得和最小,那么就是简单的排序,去掉前k大的(注意l ...
- HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题
分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...
随机推荐
- Servlet的response输出到页面时乱码的解决方法
package com.mhb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...
- 8、SpringMVC源码分析(3):分析ModelAndView的形成过程
首先,我们还是从DispatcherServlet.doDispatch(HttpServletRequest request, HttpServletResponse response) throw ...
- P25、面试题1:赋值运算符函数
题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStr ...
- Linux3.4内核的基本配置和编译
转载自:http://www.embedu.org/Column/Column634.htm 作者:李昕,华清远见研发中心讲师. 了解Linux3.4内核的特性及新增功能,掌握Linux内核的编译过程 ...
- BZOJ 2339 卡农(组合数学)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2339 题意: 思路: i64 Pow(i64 a,i64 b,i64 mod){ ...
- SetCapture、ReleaseCapture、GetCapture
正常情况下,鼠标指针位于哪个窗口区域内,鼠标消息就自动发给哪个窗口.如果调用了SetCapture,之后无论鼠标的位置在哪,鼠标消息都发给指定的这个窗口,直到调用ReleaseCapture或者调用S ...
- LA 4636 (贪心) Cubist Artwok
题意: 一个由若干小正方体组成的图形,给出它的正视图和侧视图,求满足条件的最少小正方体的个数. 分析: 虽说是一道简单的贪心,可一直没有太好的思路. 又一次可耻地看了别人的题解. http://blo ...
- Java [Leetcode 203]Remove Linked List Elements
题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...
- Android平台下实现录音及播放录音功能的简介
录音及播放的方法如下: package com.example.audiorecord; import java.io.File; import java.io.IOException; import ...
- <一>面向对象分析之面向对象和面向过程
面向对象 ---->注重的是拆分,组装. ---->封装,继承,多态,复用(只是现象) ---->面向对象变成的目标从来就不是复用.相反,对 ...