o****i 发帖数: 1706 | 1 我写的是
/**
* Definition for a point.
* class Point {
* int x;
* int y;
* Point() { x = 0; y = 0; }
* Point(int a, int b) { x = a; y = b; }
* }
*/
public class Solution {
public int maxPoints(Point[] points) {
Point p1 = new Point();
Point p2 = new Point();
int maxCount = 0;
if(points.length == 1){
return 1;
}
for(int i=0;i
boolean isSame = true;
p1 = points[i];
... 阅读全帖 |
|
r**********1 发帖数: 13 | 2 DP可以这样做吧,就是给定个单词,在其左右不停添加新字母(a-z,26个),看新单
词在不在字典里,取最大长度
int findlongest(string W[], int n){
先建个hashtable包含所有单词
int longest = 0;
for i=1 to n //扫描每个单词
{
string w = W[i]; //当前的单词
int t = 1+max(furthertest(W[i], 0), furthertest(W[i], 1));
longest = max(t, longest);
}
return longest;
}
int furthertest(string s, bool tryleft)
{
int maxcount = 0;
if (tryleft) //if tryleft==1, 往左边添
{
for (int i=0; i < 26; ++i)
{
string newword(1, i+'a');
... 阅读全帖 |
|
p*****2 发帖数: 21240 | 3 来自主题: JobHunting版 - 上一道题吧
可以用stack 和 dp。不过我也是在有提示的情况下做出来的。我本来是hbase的思路。
但是做不对。没想到你那个思路。你这么快能想到正确的解法还是挺赞的。
public class test
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String str=in.next();
int[] dp=new int[str.length()];
Arrays.fill(dp,-1);
Stack stack=new Stack();
int max=0;
int maxcount=0;
for(int i=0;i
{
char c=str.charAt(i);
if(c=='(')
... 阅读全帖 |
|
c*****n 发帖数: 83 | 4 unsigned function(unsigned int array[], int length){
unsigned counter = 0;
unsigned MaxCount = 0;
unsigned IntSize = sizeof(int);
unsigned I = 1 << (IntSize-1);
for(int i = 0; i < length; ++i){
unsigned temp = array[i];
for(int j = 0; j < length; ++j){
if(I & temp){
if( counter > MaxCount) MaxCount = counter;
counter = 0;
}else{
counter += 1;
}
temp <<= 1;
}
}
return MaxCount;
} |
|
B*******1 发帖数: 2454 | 5 My code for this one:
int getMax(int a[], int size)
{
if (size == 0) return 0;
int pre = a[0], maxCount = 0, count = 1;
for (int i = 0; i < size; ) {
while (++i < size && a[i] == pre) {
count ++;
}
if (count > maxCount)
maxCount = count;
if (i == size) break;
count = 1;
pre = a[i];
}
return maxCount;
} |
|
B*******1 发帖数: 2454 | 6 My code for this one:
int getMax(int a[], int size)
{
if (size == 0) return 0;
int pre = a[0], maxCount = 0, count = 1;
for (int i = 0; i < size; ) {
while (++i < size && a[i] == pre) {
count ++;
}
if (count > maxCount)
maxCount = count;
if (i == size) break;
count = 1;
pre = a[i];
}
return maxCount;
} |
|
r*******n 发帖数: 3020 | 7 one scan solution.
using namespace std;
void mostRepeatedChar(const string& s){
if(s.size()<2){
cout<
return;
}
int count = 1;
int maxCount = -1;
string result;
for(int i=1; i
if(s[i] == s[i-1]&& i!=s.size()-1){
count++;
continue;
}else{
if(count>maxCount){
maxCount = count;
result.clear();
result += s[i-1];
}else if(... 阅读全帖 |
|
c*u 发帖数: 22 | 8 来自主题: JobHunting版 - 请教一道题 第一次循环把数存到HashSet
第二次循环对HashSet删减,记录最大数
最后输出
C#
int[] array = { 8, 15, 5, 7, 12, 6, 14, 13, 9, 11, 8 };
HashSet set = new HashSet();
foreach (int val in array)
if (!set.Contains(val))
set.Add(val);
int min = 0, max = 0, maxCount = 0;
while (set.Count > 0)
{
int left = 0, right = 0, count = 1;
int val = set.First();
int now = val + 1;
while (set.Contains(now))
{
count++;
set.Remove(now);
now++;
}
right = now - 1;
now... 阅读全帖 |
|
m***2 发帖数: 595 | 9 ac的一个,不知道是不是最优
public class Solution {
/**
* @param nums: A list of integers
* @param k: As described
* @return: The majority number
*/
public int majorityNumber(ArrayList nums, int k) {
if (nums == null || nums.size() == 0 || k > nums.size() || k <= 0) {
return Integer.MAX_VALUE;
}
int[] value = new int[k];
int[] count = new int[k];
for (int i = 0; i < k; i++) {
count[i] = 0;
}
... 阅读全帖 |
|
b*****e 发帖数: 131 | 10 int MaxCount(int S)
{
if(S<0 || S==1)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=MaxCount(S-p[i]);
}
return count;
} |
|
c**********e 发帖数: 2007 | 11 完整程序(C++):
#include
#include
#include
using namespace std;
long maxCount(int s, int p[], int n) {
long* count = new long[s+1];
count[0]=1;
for(int i=1;i<=s;i++) {
count[i]=0;
for(int j=0;j
if(i-p[j]>=0) count[i]+= count[i-p[j]];
}
}
return count[s];
}
int main() {
int x[3];
x[0]=2;
x[1]=3;
x[2]=7;
cout << maxCount(47,x,3) << endl;
return 0;
} |
|
b*****e 发帖数: 131 | 12 int MaxCount(int S)
{
if(S<0 || S==1)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=MaxCount(S-p[i]);
}
return count;
} |
|
c**********e 发帖数: 2007 | 13 完整程序(C++):
#include
#include
#include
using namespace std;
long maxCount(int s, int p[], int n) {
long* count = new long[s+1];
count[0]=1;
for(int i=1;i<=s;i++) {
count[i]=0;
for(int j=0;j
if(i-p[j]>=0) count[i]+= count[i-p[j]];
}
}
return count[s];
}
int main() {
int x[3];
x[0]=2;
x[1]=3;
x[2]=7;
cout << maxCount(47,x,3) << endl;
return 0;
} |
|
E*******0 发帖数: 465 | 14 for (int i = 0; i < size; ) {
count = 1;
pre = a[i];
while (++i < size && a[i] == pre) {
count ++;
}
if (count > maxCount)
maxCount = count;
}
这样写会不会清楚些?感觉刚才那样写有点乱。
不过题目比较简单,无所谓了。我刚才只是提出我的个人意见而已。 |
|
E*******0 发帖数: 465 | 15 for (int i = 0; i < size; ) {
count = 1;
pre = a[i];
while (++i < size && a[i] == pre) {
count ++;
}
if (count > maxCount)
maxCount = count;
}
这样写会不会清楚些?感觉刚才那样写有点乱。
不过题目比较简单,无所谓了。我刚才只是提出我的个人意见而已。 |
|
p*****2 发帖数: 21240 | 16 这不是DP吗?
int MaxCount(int S)
{
if(S<0)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=(S-p[i]);
}
} |
|
k***t 发帖数: 276 | 17 我也算了个271405。不过你贴得code好像不全吧。
发信人: peking2 (myfacebook), 信区: JobHunting
标 题: Re: 一道题:number of permutation是 for a total score
发信站: BBS 未名空间站 (Tue Jan 31 06:43:11 2012, 美东)
这不是DP吗?
int MaxCount(int S)
{
if(S<0)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=(S-p[i]);
}
} |
|
k***t 发帖数: 276 | 18 赞。
随手写得几行和我洋洋洒洒写得一大段结果一致!
几点交流。
0。存一个S维的maxCount数组,就可以变成DP。
1。S==1 的判断不必要吧,也不通用。
2。S<0 的判断只适用于正整数,这里只说整数,可能也不太通用。 |
|
p*****2 发帖数: 21240 | 19 这不是DP吗?
int MaxCount(int S)
{
if(S<0)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=(S-p[i]);
}
} |
|
k***t 发帖数: 276 | 20 我也算了个271405。不过你贴得code好像不全吧。
发信人: peking2 (myfacebook), 信区: JobHunting
标 题: Re: 一道题:number of permutation是 for a total score
发信站: BBS 未名空间站 (Tue Jan 31 06:43:11 2012, 美东)
这不是DP吗?
int MaxCount(int S)
{
if(S<0)
return 0;
if(S==0)
return 1;
int count=0;
for(int i=0;i
{
count+=(S-p[i]);
}
} |
|
k***t 发帖数: 276 | 21 赞。
随手写得几行和我洋洋洒洒写得一大段结果一致!
几点交流。
0。存一个S维的maxCount数组,就可以变成DP。
1。S==1 的判断不必要吧,也不通用。
2。S<0 的判断只适用于正整数,这里只说整数,可能也不太通用。 |
|
p*****2 发帖数: 21240 | 22
我现在是这么输出的,你看有什么问题吗?今天搞了一个上午了。Heap里存的是Long型
if(maxCount>minCount) return maxHeap.head.toString
else{
val sum=maxHeap.head+minHeap.head
if(sum%2==0) return (sum/2).toString
else return (sum/2).toString+".5"
} |
|
p*****2 发帖数: 21240 | 23 改了改,还是有一个test case fail。这个输出有问题吗?
if(maxCount>minCount) return maxHeap.head.toString
else{
val sum:Long=maxHeap.head+minHeap.head
if(sum%2==0) return (sum/2).toString
else return "%.1f".format(sum.toDouble/2)
} |
|
u*****o 发帖数: 1224 | 24 第二题可以用MULTIMAP里的COUNT吗?先建TABLE,然后扫一遍,记录MAXCOUNT? |
|
p*****3 发帖数: 488 | 25 要多线程吗,不用的话就
int stateTime, stateCount;
boolean canCall() {
int curTime = systimestamp();
if (curTime != stateTIme) {
stateTime = curTime;
stateCount = 1;
return true;
}
if (curCount >= maxCount)
return false;
curCount ++;
return true;
} |
|
d*******2 发帖数: 47 | 26 Hi all
Thanks for reading it. I am working on a sas/graph project for couple days
without any progress. Kind of stressful and wonder if anyone here can give
me some suggestions.I would really appreciate your input!
This is the first time I used sas/graph function.
I had the dataset
_NAME_ _1 _2 _3 _4 maxcount
Gen1 1.11 1.88 1.03 0.628688619 1.88
Gen2 1.17 1.35 2.01 1.190167356 2.01
and codes
PROC GCHART data=WORK.diagram_final;
vBA |
|