BestCoder Round #85
来源:互联网 发布:舞台效果图设计软件 编辑:程序博客网 时间:2024/06/05 02:10
HDU【5776】——sum
|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≤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.
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的倍数。搞一下序列模m的前缀和,判断是不是存在相同的值。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <list>#include <algorithm>using namespace std;const double PI = acos(-1.0);const double e = exp(1);typedef long long LL;int T;int n,m;int a[111111];int vis[5500];int main(){ scanf("%d",&T); while(T--) { scanf("%d %d",&n,&m); a[0] =0; memset(vis,0,sizeof(vis)); for(int i = 1;i<=n;i++) { scanf("%d",&a[i]); a[i] = (a[i-1]+a[i])%m; } bool flag = false; vis[0] = true; for(int i = 1;i<=n;i++) { if(vis[a[i]]) { flag = true; break; } vis[a[i]] = true; } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
HDU【5777】——domino
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
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
首先骨牌只要考虑都往右推,其次能带倒骨牌的前提是高度大于等于距离+1。所以如果推一次,那么就是骨牌高度=离下一块骨牌距离+1. 把第一块左边距离设为无穷大,能推nk次,那么就是找nk块左边距离最大的向右推倒即可,所以只需要排序找到前nk-1大的距离
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <list>#include <algorithm>using namespace std;const double PI = acos(-1.0);const double e = exp(1);typedef long long LL;int T;int n,k;int a[110000];int main(){ scanf("%d",&T); while(T--) { scanf("%d %d",&n,&k); LL sum = n; for(int i = 0; i<n-1; i++) { scanf("%d",&a[i]); sum+=a[i]; } if(k>=n) { sum = n; } else { sort(a,a+n-1); for(int i = n-2; i>=(n-1-k+1); i--) { sum-=a[i]; } } printf("%I64d\n",sum); } return 0;}
HDU【5778】——abs
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.
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≤10
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,求正整数
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <list>#include <algorithm>using namespace std;const double PI = acos(-1.0);const double e = exp(1);const int INF = 0x3f3f3f3f;typedef long long LL;const int Max = 1e6+100;bool vis[Max];LL pr[Max];void Init(){ pr[0] = 0; for(int i = 2; i<Max; i++) { if(!vis[i]) { pr[++pr[0]] = i; for(int j = i+i; j<Max; j+=i) { vis[j] = true; } } }}bool ok(LL s){ if(s == 1) return false; for(int i = 1; i<=pr[0] && pr[i] * pr[i] <=s ; i++) { if(s%(pr[i]*pr[i]) ==0) return false; } return true;}LL Check(LL s,LL d){ while(s>0) { if(ok(s)) return s; s+=d; } return -1;}int main(){ Init(); int T; LL x; cin>>T; while(T--) { cin>>x; if(x == 1) { printf("3\n"); continue; } if(x == 2) { printf("2\n"); continue; } LL y = sqrt(x); LL a1 = Check(y,-1); LL a2 = Check(y+1,1); LL ans = min(abs(a1*a1-x),abs(a2*a2-x)); cout<<ans<<endl; } return 0;}
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85题解
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85 前三题
- BestCoder Round #85题解
- BestCoder Round #85题解报告
- BestCoder Round #85 1001 1002
- BestCoder Round #85 题解(待续)
- BestCoder Round #85-1003 abs
- BestCoder Round #85 前三题题解
- Bestcoder round#85 解题报告
- BestCoder Round #85 1001 sum
- BestCoder Round #85题解报告
- BestCoder Round #85-1005 gcd
- 判断Intent是否存在,PakageManager.GET_ACTIVITIES报错
- UE4接口的使用及对象回收机制
- 华为OJ 初级:合唱队
- 网狐经典版机器人配置
- 进程组,作业,会话,精灵进程
- BestCoder Round #85
- Qos知识简介
- Gym 100971G Repair
- 百练 最简真分数
- Linux基础----------文件 IO 之 read 和 write (readn 、writen、readline)
- spring各个版本下载
- 分布式理论:关于一致性讨论
- 生成javadoc
- 后缀数组总结