3
30
2015
0

Tyvj 1002 谁拿了最多奖学金

#include <iostream>
#include <cstdio>
using namespace std;
string name,king;
int n,avrg,grde,papr;
char ofcl,west;
long long tot,best,t;
int main()
{
	cin>>n;
	for (int i=0;i<n;++i) {
		t=0;
		cin>>name>>avrg>>grde;
		getchar(); ofcl=getchar();
		getchar(); west=getchar(); getchar();
		cin>>papr;
		if (avrg>80 && papr>0) t+=8000;
		if (avrg>85 && grde>80) t+=4000;
		if (avrg>90) t+=2000;
		if (avrg>85 && west=='Y') t+=1000;
		if (grde>80 && ofcl=='Y') t+=850;
		if (t>best) {
			best=t; king=name;
		}
		tot+=t;
	}
	cout<<king<<endl<<best<<endl<<tot;
	return 0;
}
Category: 题解 | Tags: Tyvj 模拟
3
30
2015
0

Tyvj 1001 第K极值

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int a[10000],m,n,k;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;++i)
		scanf("%d",&a[i]);
	sort(a,a+n);
	m=a[n-k]-a[k-1];
	if (m<2) {
        printf("NO\n%d",m);
        return 0;
	}
	for (int i=2;i<=sqrt(m);++i)
		if (m%i==0) {
			printf("NO\n%d",m);
			return 0;
		}
	printf("YES\n%d",m);
	return 0;
}
Category: 题解 | Tags: Tyvj 模拟
3
11
2015
0

COGS 40 [NOIP1999] 回文数

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

string m,toc="0123456789abcdef";
int n,cnt;

string rev(string s)//翻转字符串
{
    string res="";
    for (int i=s.size();i>0;--i)
        res+=s[i-1];
    return res;
}

bool hw(string s)//判断是否为回文
{
    string s1,s2;
    s1=s.substr(0,s.size()/2);
    s2=s.substr(s.size()/2+s.size()%2,s.size()/2);
    return s1==rev(s2);
}

int main()
{
    freopen("huiwen.in","r",stdin);
    freopen("huiwen.out","w",stdout);
    cin>>n>>m;
    for (int i=0;i<m.size();++i)
        if (isalpha(m[i])) m[i]=m[i]-'a'+10;//若为字母,转化为相应数字
        else m[i]=m[i]-'0';//转化为相应数字
    string a,b; int g;
    while (cnt++<=30){
        a=rev(m); b=""; g=0;
        for (int i=0;i<m.size();++i){//高精度加法
            b+=char((a[i]+m[i]+g)%n);
            g=(a[i]+m[i]+g)/n;
        }
        if (g>0) b+=char(1);//处理进位
        m=b;
        if (hw(b)) {//若回文,输出并结束
            for (int i=0;i<b.size();++i)
                b[i]=toc[b[i]];
            cout<<b<<endl<<cnt;
            return 0;
        }
    }
    cout<<"impossible";
    return 0;
}
Category: 题解 | Tags: NOIP COGS 模拟 高精度

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