無駄が多いのでそのうち修正
/******************************************
* 2012/06/29 *
* AOJ Volume0 0030 Sum of Integers *
* wrote crane *
*******************************************/
#include<iostream>
using namespace std;
int num[] ={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n=0; //n個の数字
int s=0; //n個の数字の和がsとなる
int count;
void solve(int x, int sum, int c);
int main(){
while(cin >> n >> s, (n||s)){
count = 0;
solve(n, s, 0);
cout << count << endl;
}
return 0;
}
void solve(int x, int sum, int c){//x->n個の数字 , sum->和 c->numカウント用
if(x == 0 && y==0 && c==10){
count++;
return;
}else if(9<c || x<0 || y<0){
return;
}else{
int a=y-num[c];
c++;
solve(x, y, c); //足さない
solve(x-1, a,c);//足す
}
return;
}
Amazon
2012年7月4日水曜日
AOJ Volume0 0025: Hit and Blow
/***********************
* 2012/06/29 *
* AOJ Volume0 0025 *
* Hit and Blow *
* crane *
************************/
#include<iostream>
using namespace std;
int main(){
int a[4]; //Aさんの思い浮かべた4つの数字
int b[4]; //Bさんの思い浮かべた4つの数字
while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
int hit=0;
int blow=0;
for(int i=0; i<4; i++)
cin >> b[i];
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
if(a[i] == b[j])
if(i==j)
hit++;
else
blow++;
cout << hit << " " << blow << endl;
}
return 0;
}
* 2012/06/29 *
* AOJ Volume0 0025 *
* Hit and Blow *
* crane *
************************/
#include<iostream>
using namespace std;
int main(){
int a[4]; //Aさんの思い浮かべた4つの数字
int b[4]; //Bさんの思い浮かべた4つの数字
while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
int hit=0;
int blow=0;
for(int i=0; i<4; i++)
cin >> b[i];
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
if(a[i] == b[j])
if(i==j)
hit++;
else
blow++;
cout << hit << " " << blow << endl;
}
return 0;
}
ラベル:
AOJ,
AOJ_Volume0,
探索
登録:
投稿 (Atom)