湘潭ccpc2018

链接:https://cn.vjudge.net/contest/296332#overview

A.

阅读理解题。找出引用数大于h的至少有h篇的论文那个最大的h数。(我晕了)

比如 第二个样例 2  1(下标0) 2(下标1) 3(下标2)

其中下标表示引用数,而ai表示论文的数论,3(下标2)表示引用了2页的论文有3篇。

这里引用数大于2的为3篇,引用数大于1的为5篇,引用数大于0的为6篇。

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

long long a[200005];

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i = 0;i<=n;++i) scanf("%lld",&a[i]);
		for(int i = n-1;i>=0;--i) a[i] += a[i+1];
		for(int i = n;i>=0;--i){
			if(a[i] >= i){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}

F. 

这题比较要求精度判断,直接相除会错。

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

struct node{
	long double a,b,c;
	int id;
}a[1005];

/*bool cmp(node a,node b){
	if(fabs((a.a+a.b)*(b.a+b.b+b.c) - (b.a+b.b)*(a.a+a.b+a.c)) < 1)
	return a.id < b.id;
	return (a.a+a.b)*(b.a+b.b+b.c) < (b.a+b.b)/(a.a+a.b+a.c);
}*/

bool cmp(node a,node b){
	    long double aa=(a.a+a.b)*(b.a+b.b+b.c);
        long double bb=(b.a+b.b)*(a.a+a.b+a.c);
        //cout<<aa<<" "<<bb<<endl;
        //cout<<a.a<<" "<<a.b<<" "<<a.c<<endl;
        //cout<<b.a<<" "<<b.b<<" "<<b.c<<endl;
        //cout<<(b.a+b.b)<<" "<<endl;
        if(fabs(aa-bb)<1)
            return a.id<b.id;
        else
            return aa<bb;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i = 1;i<=n;++i){
			cin>>a[i].a>>a[i].b>>a[i].c;
			//cout<<(a[i].a+a[i].b)*1.0/(a[i].a+a[i].b+a[i].c)<<endl;
			a[i].id = i;
		}
		sort(a+1,a+1+n,cmp);
		int ok = 0;
		for(int i = 1;i<=n;++i){
			if(ok == 0)
			ok = 1;
			else
			cout<<" ";
			cout<<a[i].id;
		}
		cout<<endl;
	}
	return 0;
}

K 2018

题意。给定a,b,c,d,让 a<=x<=b,c<=y<=d,使x*y是2018倍数,求有多少组x,y。

因为2018的因数只有1,2,1009,2018,所以个数 = 2018个数 + 1009个数*偶数个数 - 重复个数。

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

int main(){
	long long sum,l1,l2,r1,r2,p1,p2,t1,t2,o1,o2; //p 2018倍数 t 1009倍数 o 偶数个数 
	while(~scanf("%lld%lld%lld%lld",&l1,&r1,&l2,&r2)){
		sum = 0;
		p1 = r1/2018 - l1/2018;
		if(l1 % 2018 == 0) ++p1;
		p2 = r2/2018 - l2/2018;
		if(l2 % 2018 == 0) ++p2;
		//cout<<p1<<" "<<p2<<endl;
		sum += p1 * (r2-l2+1) + p2 * (r1-l1+1) - p1*p2;
		//cout<<sum<<endl;
		t1 = r1/1009 - l1/1009;
		if(l1 % 1009 == 0) ++t1;
		t2 = r2/1009 - l2/1009;
		if(l2 % 1009 == 0) ++t2;
		t1 -= p1;
		t2 -= p2;
		o1 = r1/2 - l1/2;
		if(l1 % 2 == 0) ++o1;
		o2 = r2/2 - l2/2;
		if(l2 % 2 == 0) ++o2;
		o1 -= p1;
		o2 -= p2;
		sum += t1*o2 + t2*o1;
		cout<<sum<<endl;
	} 
	return 0;
}

G.

题意,给定2个只包含'a','b','c',字符串A,B,可以在A上任意增加或删除"aa","bb","abab",问能否让a变为b。

因为字符串中的c是不能变的,所以以字符串的’c'为间隔检查字符串中的子字符串,由样例一得知相邻的ab是可以任意调换顺序的,所以可以将子字符串全部‘a’移到最左边,‘b'移到最右边,然后删除aa,bb,那么可以得知如果a,b数量奇偶性不想听则为"No”

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

string a,b;

int main(){
	int cn1,cn2,an1,an2,bn1,bn2;
	while(cin>>a>>b){
	    cn1 = cn2 = 0;
	    a += "c";
	    b += "c";
	    for(int i = 0;i<a.size();++i){
	    	if(a[i] == 'c') ++cn1;
		}
		for(int i = 0;i<b.size();++i){
			if(b[i] == 'c') ++ cn2;
		}
		if(cn1 != cn2){
			cout<<"No\n";
			continue;
		}
		int i = 0,j = 0,ok = 1;
		while(i < a.size()&&j < b.size()){
			an1 = an2 = bn1 = bn2 = 0;
			while(i<a.size()&&a[i] != 'c'){
				if(a[i] == 'a') ++an1;
				else ++bn1;
				++i;
			}
			++i;
			while(j<b.size()&&b[j] != 'c'){
				if(b[j] == 'a') ++an2;
				else ++bn2;
				++j;
			}
			++j;
			if(an1%2 != an2%2 || bn1%2 != bn2%2){
				ok = 0;
				break;
			}
		}
		if(ok == 1)
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/dukig/article/details/89433761
今日推荐