CareerCup perform increment operation on ai = ai+1 and decrements operation on aj = aj - 1
2014-03-09 16:09
330 查看
Given an array of n elements (a1,a2,..ai,...,an). You are allow to chose any index i and j, such that (i!=j) and allow to perform
increment operation on ai = ai+1 and decrements operation on aj = aj - 1 infinite number of times. How many maximum number of elements you can find that have same number.
example 1:
1 4 1
ans: 3
example 2:
2 1
ans : 1
---------------------------
Increment and decrement could be performed more than once...
increment operation on ai = ai+1 and decrements operation on aj = aj - 1 infinite number of times. How many maximum number of elements you can find that have same number.
example 1:
1 4 1
ans: 3
example 2:
2 1
ans : 1
---------------------------
Increment and decrement could be performed more than once...
uint max_equal(int *a, uint n) { int s = 0; for (uint i = 0; i < n; i++) { s = (s + a[i])%n; // avoid overflow issues at slight cost of performance. // assumes % returns 0 to n-1. } return s==0 ? n : n-1; }
相关文章推荐
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路+二分
- AIZU 0009
- SharePoint 2010 出错! HTTP Error 503. The service is unavailable
- SharePoint 2010 出错! HTTP Error 503. The service is unavailable
- AIZU 0005
- sleep() 和 wait() 有什么区别?
- RedHat 学习笔记【3】RAID详细配置讲解
- Notes on Brain Study
- DP基础问题若干(ACM/ICPC) 来自http://blog.csdn.net/accry/article/details/6607593
- 2013款MacbookAir安装win7的坎坷经历
- R语言的高质量图形渲染库Cairo
- Climbing Stairs
- Corosync/Openais+Pacemaker+ISCSI+OCFS:构建高可用Web群集
- Simple screenshot that explains the singleton invocation.
- 怎样用UltraISO制作U盘系统安装盘
- 机器学习与人工智能学习资源导引
- Simple screenshot that explains the non-static invocation.
- HDU 4308 Saving Princess claire_(简单BFS)
- STL源码分析《4》----Traits技术
- STL源码分析《4》----Traits技术