2010年12月21日
SRM491 Div2
撃墜のおかげでレートがあがったorz
250p OneDigitDifference ○
数字がひとつ違いで一番小さいものを求める問題。0のときは1でそれ以外は一番上の桁を0にしたものになるというもの。
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class OneDigitDifference {
public:
int getSmallest(int N) {
if(N==0) return 1;
int res=0;
int a=N;int b=0;
while(N>10){
b++;
N/=10;
}
res=a-N*(int)pow(10.0,b);
return res;
}
};
500p FoxMakingDiceEasy ×
ひとつの目が1からNで両面の和がK以上のさいころが何通りできるか求める問題。数学ゲー
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class FoxMakingDiceEasy {
public:
int theCount(int N, int K) {
int res=0;
for(int a=1;a<=N-5;++a){
for(int b=N;b-a>=5;--b){
int t=(b-a-1)/2;
if(a+b>=K) res+=t*(t-1);
}
}
return res;
}
};