sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 853 Accepted Submission(s): 398
Total Submission(s): 853 Accepted Submission(s): 398
鸽巢原理 ;
Problem Description
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≤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≤100000 , 1≤m≤5000 ).
2.The second line contains n positive integers x ( 1≤x≤100 ) according to the sequence.
For each test case, there are two lines:
1.The first line contains two positive integers n, m ( 1≤n≤100000 , 1≤m≤5000 ).
2.The second line contains n positive integers x ( 1≤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
Source
Recommend
wange2014 | We have carefully selected several similar problems for you:
5780
5779
5778
5777
5775
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#define LL long long
using namespace std;
const int N=1e5+10;
int A[N];
int main()
{
int t,n,m,x;
scanf("%d",&t);
while(t--)
{
int sum=0;
scanf("%d%d",&n,&m);
memset(A,0,sizeof(A));
int flag=0;
A[0]=1;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
(sum+=x)%=m;
if(A[sum])
{
flag=1;
}
else
A[sum]++;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
domino
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 593 Accepted Submission(s): 305
Total Submission(s): 593 Accepted Submission(s): 305
思路:假设一开始每个骨牌的高度都为一,那么他们加上间距就可以推倒他前面的那块,那么可以贪心的加距离最小的那些,n-k个;
Problem Description
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≤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≤100000 )
The second line has n - 1 integers, the distance of adjacent domino d, 1≤d≤100000
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≤100000 )
The second line has n - 1 integers, the distance of adjacent domino d, 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
Source
Recommend
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#define LL long long
using namespace std;
const int N=1e5+10;
LL A[N];
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
LL sum=n;
n--;
for(int i=0;i<n;i++)
scanf("%lld",&A[i]);
sort(A,A+n);
n-=m;
for(int i=0;i<=n;i++)
sum+=A[i];
printf("%I64d\n",sum);
}
return 0;
}
abs
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1227 Accepted Submission(s): 425
Total Submission(s): 1227 Accepted Submission(s): 425
开根后上下枚举,找最小;
Problem Description
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;
const int N=1e5+10;
LL prime[N>>2];
bool flag[N];
LL p[N>>2];
int k;
void getprime()
{
k=0;
for(LL i=2;i<N;i++)
{
if(!flag[i])
{
prime[k]=i;p[k++]=i*i;
for(LL j=i*i;j<N;j+=i)
{
flag[j]=1;
}
}
}
}
bool ok(LL x)
{
for(int i=0;i<k;i++)
{
if(x%p[i]==0)
return 0;
}
return 1;
}
int main()
{
int t;
LL x;
getprime();
scanf("%d",&t);
while(t--)
{
scanf("%lld",&x);
LL m=(LL)(sqrt(x)+0.5);
LL ans=1e18;
for(LL i=m+1;;i++)
{
if(ok(i))
{ans=min(ans,abs(i*i-x));break;}
}
for(LL j=m;j>=2;j--)
{
if(ok(j))
{ans=min(ans,abs(x-j*j));break;}
}
printf("%I64d\n",ans);
}
return 0;
}
Problem Description
Given a number x, ask positive integer
y≥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.
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≤50
)
For each test case,the single line contains, an integer x ( 1≤x≤1018 )
For each test case,the single line contains, an integer x ( 1≤x≤1018 )
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
Source
Recommend