SRM 146 Div2
250
要約すると配列で渡された数字の中で、同じ数字の合計がもっとも大きくなる数字を選べみたいな問題
こんな感じで回答
#include<vector>
class YahtzeeScore{
public:
int maxPoints(std::vector<int>);
};
int YahtzeeScore::maxPoints(std::vector<int> toss){
int i,count[7],chc;
int ans = 0;
for( i = 0; i < 6; i++){
count[i] = 0;
}
for(i = 0; i < 5; i++){
count[toss[i]] ++;
}
for(int j = 1; j < 7; j++){
chc = 1;
for(i = 0; i < count[j]; i++){
chc = chc * count[j];
}
if(chc > ans){
ans = j;
}
}
return (ans);
}
思いっきり間違ってるでござる。掛け算じゃねぇし。
#include<vector>
class YahtzeeScore{
public:
int maxPoints(std::vector<int>);
};
int YahtzeeScore::maxPoints(std::vector<int> toss){
int i,count[7];
int ans = 0;
for( i = 0; i < 6; i++){
count[i] = 0;
}
for(i = 0; i < 5; i++){
count[toss[i]] += toss[i];
}
for(i = 0; i < 6; i++){
if(ans < count[i]) ans = count[i];
}
return (ans);
}
多分これで通るんじゃないかなぁ… 問題文良く理解できなかったから要素数が5個固定なのかは分からないけど。500
要約するとheight * widthのグリッドの中に正方形でない四角形のグリッドがいくつあるか こんな感じに回答
#include<algorithm>
class RectangularGrid{
public:
long long countRectangles(int width,int height);
};
long long RectangularGrid::countRectangles(int width,int height){
long long w = width, h = height, x, y, xv, yv, xh, yh, max, ans;
max = std::max(height, width);
x = 1;
ans = 0;
while(x <= max){
y = x;
while(y <= max){
xv = yv = xh = yh = 0;
if(x == y){
y++;
continue;
}
xv = h - (x - 1);
yv = w - (y - 1);
xh = w - (x - 1);
yh = h - (y - 1);
if(xv * yv < 0 && xh * yh < 0){
y++;
continue;
}
if(xv * yv > 0)ans += xv * yv;
if(xh * yh > 0)ans += xh * yh;
y++;
}
x++;
}
return ans;
}
で、何度やってもバグがとれなくて、諦めて満点解答見に行ったら、縦と横は別々で数えてたと。これはもう…class RectangularGrid{
public:
long long countRectangles(int width,int height);
};
long long RectangularGrid::countRectangles(int width,int height){
long long w = width, h = height, x, y, ans;
ans = 0;
for(x = 1; x <= w; x++){
for(y = 1; y <= h; y++){
if(x == y) continue;
ans += ((w - (x - 1)) * (h - (y - 1)));
}
}
return ans;
}
なにも頭ひねったり凝ったりすること無かったのよ。シンプルでよかった。これはもう経験不足としか言いようがない。というわけでひどい結果でした。
0 件のコメント:
コメントを投稿