1. 题目
2. 代码
对付这种题目,最简单的办法:
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "2"<< endl;
return 0;
}
比较傻的办法(手动狗头
#include <iostream>
using namespace std;
bool h[11] = {false}; //散列地址是否被填入
int findh(int n){
int tmp = (3*n) % 11;
if(h[tmp]){
for(int i=1; i<=10; i++){
if(h[(tmp+i)%11]) continue;
else{
h[(tmp+i)%11] = true;
return i+1;
}
}
}
h[tmp] = true;
return 1;
}
int main(int argc, char** argv) {
int list[8] = {22, 41, 53, 46, 30, 13, 01, 67};
int sum = 0;
for(int i=0; i<8; i++){
// cout << "t: " << i << "\t" << list[i] << "\t" << findh(list[i]) << endl;
sum += findh(list[i]);
}
cout << sum/8 << endl;
return 0;
}