第一题: 刚开始想烦了, 用了宽度搜索.
#include <bits/stdc++.h>
using namespace std;
const int MM = 100000;
bool zhishu[MM];
void init(int R1 ){
}
int jisuan(int x, int y){
int xx[5];
int yy[5];
for(int i=0;i<5;i++){
xx[i] = x % 10; x= x/10;
yy[i] = y % 10; y= y/10;
}
int sum=0;
for(int i=0;i<5;i++){
int bo= abs( xx[i]- yy[i] );
if(bo > 5) bo= 10-bo;
sum += bo;
}
return sum;
}
void shai(){
memset(zhishu,true, sizeof(zhishu));
for(int i=2;i<MM;i++ ){
for(int j=2;i*j<MM;j++){
if(zhishu[i]) zhishu[i*j]=false;
}
}
}
int main()
{
int chushi;
cin >> chushi;
shai();
int ans=-1; int mymin=99999999;
for(int i=10000;i >2; i--)
{
if( zhishu[i] && i!=chushi){
// cout << i << "|" << endl;
int ji= jisuan(i, chushi);
if( mymin > ji )
{
mymin =ji;
ans = i;
}
}
}
if( ans>9999) cout << ans;
else{
if(ans>999) cout << 0 <<ans;
else if( ans>99) cout << 0 << 0 << ans;
else if(ans > 9) cout << 0 << 0 << 0 << ans;
else cout << 0 << 0 << 0 << 0 << ans;
}
return 0;
}
第二题:通过了
#include <bits/stdc++.h>
using namespace std;
const int MM = 100;
long long R[MM+2];
int N,R1;
vector<int> h;
void init(int x ){
R[1] = x;
for(int i=2 ;i <=MM ;i++)
{
R[i] =(( R[i-1]*6807 + 2831 ) % 201701) ;
// cout <<i << ": "<< R[i] << endl;
}
for(int i=1;i <=MM ;i++){
R[i] = R[i] % 10;
// cout <<i << ": "<< R[i] << endl;
}
}
int main()
{
#ifdef DEBUG
freopen("water.in", "r",stdin);
#else
freopen("water.in", "r",stdin);
freopen("water.out", "w",stdout);
#endif // DEBUG
cin>>N>>R1;
memset(R, 0 ,sizeof(R));
init(R1);
for(int i=1;i<=N;i++)
{
cout << i;
if( ( R[i]>R[i-1]) && ( R[i]>R[i+1] ) )
h.push_back(i);
}
#ifdef DEBUG
for( int i=0 ; i < h.size(); i++){
cout << i <<" afsd fads asfdasdf " << R[ h[i] ] <<endl;
}
#endif // DEBUG
assert( h.size()>0);
int result=0;
for(int i=0 ;i<h.size()-1;i++){
int left= h[i]; int right= h[i+1];
int zui = min( R[left], R[right] );
//cout << "left" << left << "right"<<right;
int ans=0;
for(int x=left+1; x<=right-1; x++){
ans += (zui- R[x]);
}
result+=ans;
}
cout << result;
return 0;
}
第三题, 终于铜鼓了
#include <bits/stdc++.h>
using namespace std;
const int MM = 100;
long long R[MM];
int N,K,R1;
void init(int x ){
R[0] = x;
for(int i=1;i <MM ;i++)
{
R[i] =(( R[i-1]*6807 + 2831 ) % 201701) ; //刚开始写成了 2813 悲催了
cout <<i << ": "<< R[i] << endl;
}
for(int i=0;i <MM ;i++)
R[i] = R[i] % 4;
}
string produce(){
string s;
for(int i=0;i<N;i++ ){
switch( R[i]){
case 0: s.append("A");break;
case 1: s.append("T");break;
case 2: s.append("C");break;
case 3: s.append("G");break;
}
}
return s;
}
int main()
{
#ifdef DEBUG
freopen("genome.in", "r",stdin);
#else
freopen("genome.in", "r",stdin);
freopen("genome.out", "w",stdout);
#endif // DEBUG
cin>>N>>K>>R1;
init(R1);
set<string> set1;
string g = produce();
cout << "g is::"<<g<< endl;
for(int i=0;i<=N-K;i++)
{
cout << g.substr(i,K)<<endl;
string t = g.substr(i,K);
set1.insert(t);
}
cout << set1.size();
return 0;
}
川菜的。稍稍看看。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010
string str;
int n,k,R;
set<string>genome;
void createstr(int n,int R)
{
str[0]=R%4+'0';
for(int i=1;i<=n;i++)
{
R=(R*6807+2831)%201701;
str[i]=R%4+'0';
}
}
int main()
{
#ifndef Debug
freopen("genome.in
","r",stdin);
freopen("genome.out","w",stdout);
#endif
cin>>n>>k>>R ;
str.resize(n);
createstr(n,R);
for(int i=0;i<=n-k;i++)
genome.insert(str.substr(i,k));
cout<<genome.size()<<endl;
return 0;
}