7
7
2015
0

XJOI 1425 楼梯

#include <iostream>
#include <climits>
using namespace std;

long long h[51],b[51]={1};
int n,f[51];

int main()
{
	cin>>n;
	for (int i=1;i<=n;++i){
		cin>>h[i];
		b[i]=b[i-1]<<1;
	}
	for (int i=2;i<=n;++i){
		f[i]=INT_MAX/3;
		for (int j=1;j<i;++j)
			for (int k=j;k>0;--k)
				if (b[j-k]+h[k]>=h[i])
					f[i]=min(f[j]+j-k+1,f[i]);
		if (f[i]==INT_MAX/3){
			cout<<-1;
			return 0;
		}
		//cout<<i<<'='<<f[i]<<endl;
	}
	cout<<f[n];
	return 0;
}
Category: 题解 | Tags: XJOI 动规
7
6
2015
0

XJOI 1423 交换

#include <iostream>
using namespace std;


int main(){
	int ans=0;
	string a,b;
	cin>>a>>b;
	for (int i=1;i<a.size()-1;++i){
		if (a[i-1]!=a[i+1]) continue;
		for (int j=1;j<b.size()-1;++j)
			if (b[j-1]==b[j+1] && b[j-1]==a[i] && a[i-1]==b[j])
				++ans;
	}
	cout<<ans;
	return 0;
}
Category: 题解 | Tags: XJOI
6
22
2015
0

XJOI 1701 二进制除法

//中考考后第一更。我深深地感到自己实在是个大弱逼
//这题代码还是从别人那抄来的。。。
//http://www.cppblog.com/ccl0326/archive/2009/07/31/91792.html
//只好多写点注释,洗清罪名
//这美丽的代码,瞬间自惭形秽
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

string str1;
string str2;
int len1,len2;
int num1,num2;
long StrToInt(string str) //字符串转换+进制转换
{

     long reNum=0;
     int len=str.length();
     int p=0;
     for (int i=len-1;i>=0;i--)
     {
         int u=(int)pow(2,p);p++;
         switch(str[i])
         {
          case '1':reNum+=u;break;
          default:break;
         }
     }
     return reNum;
}
string IntToStr(int value)
{
       string str="";
       while (value!=0)
       {
             int x=value%2;
             if (x==0) str='0'+str; else str='1'+str;
             value=value/2;
       }
       return str;
}
void readp()
{
     cin>>str1;
     cin>>str2;
     num2=StrToInt(str2);
}
void solve()
{
     string str="";
     for (int i=0;i<str1.length();i++)
     {
         str+=str1[i];
         num1=StrToInt(str);
         if (num1>=num2) //把除数扩大10^x倍后再减,提高效率
         {
          int x=num1-num2;
          str=IntToStr(x);
         }
     }
     if (str=="") str="0"; //唯一自己写的一句话,特判
     cout<<str<<endl;
}
int main()
{
    readp();
    solve();

    return 0;
}
Category: 题解 | Tags: XJOI 数学

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com