5
2
2015
0

luogu 2378 因式分解

//90分,不想改了,用求根公式求两根即可
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

unsigned long long a[3];

string edit(int x) {
	string num="";
	if (x==0) return "x";
	int t=abs(x);
	while (t) {
		num+=t%10+'0';
		t/=10;
	}
	for (int i=0;i<num.size()/2;++i)
		swap(num[i],num[num.size()-i-1]);
	if (x>0) return "(x+"+num+")";
	else return "(x-"+num+")";
	return 0;
}

int main() {
    //freopen("in.txt","r",stdin);
	a[2]=1;
	int x; char c;
	while ((c=getchar())!=EOF) {
		if (c!='+' && c!='-') continue;
		int t; cin>>t; //cout<<'!';
		if (getchar()==EOF) {
			a[0]=t;
			if (c=='-') a[0]*=-1;
            break;
		}
		else {
            if (t==0) a[1]=1;
			else a[1]=t;
			if (c=='-') a[1]*=-1;
		}
	}
	//cout<<a[1]<<' '<<a[0]<<endl;
	int delta=sqrt(a[1]*a[1]-4*a[0]);
	int x2=(-a[1]+delta)/-2,x1=(-a[1]-delta)/-2;
	//cout<<delta<<' '<<x1<<' '<<x2<<endl;
	string s1=edit(x1),s2=edit(x2);
	if (s1==s2) cout<<s1<<"^2";
	else cout<<s1<<s2;
	return 0;
}
Category: 题解 | Tags: 模拟 数学 luogu
3
31
2015
0

Tyvj 1006 isbn

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int c,a=0; string s="";
	for (int i=1;i<=9;++i)
	{
		c=getchar(); s+=c;
		if (c=='-') --i; //序号指数字的序号,连字符不算
		else if (c!='-')
			a=(a+(c-'0')*i)%11;
	}
	getchar(); c=getchar();
	if ((a==10 && c=='X') || a+'0'==c) { //读入特判
		cout<<"Right"; return 0;
	}
	cout<<s<<'-';
	if (a==10) cout<<'X'; //输出特判
	else cout<<a;
	return 0;
}
Category: 题解 | Tags: Tyvj 模拟
3
30
2015
0

Tyvj 1003 越野跑

#include <cstdio>
#include <iostream>
using namespace std;
long long m,t;
int u,f,d,n;
char s;
int main()
{
	cin>>m>>n>>u>>f>>d;
	u+=d; f*=2; //去加回的距离一起算
	for (int i=1;i<=n;++i) {
		cin>>s;
		if (s=='u' || s=='d') t+=u; //若为坡,直接加
		else t+=f;
		if (t>m) {
			cout<<i-1; //直到超过秒数
			return 0;
		}
	}
	if (t<=m) cout<<n;
	return 0;
}
Category: 题解 | Tags: Tyvj 模拟

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