郑大校赛

总结:水平太菜;

Problem B: make pair

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 40
Submit Status Web Board

Description

pair<T,T>是c++标准模板库中一种十分有用的模板类型,它是一个二元组。我们可以用它来表示一个二维坐标点,人的身高体重等等。make_pair()函数可以方便地构造一个pair。

现在有一个长度为n的整数数组a1~an(可以存在相同的元素),将每两个元素(包括自身)make_pair(),一定能得到n2个pair。例如,[1,2,3]make_pair()后,将得到{[1,1],[1,2],[1,3], [2,1],[2,2],[2,3], [3,1],[3,2],[3,3]}。

问题是这样的,在构造出了n2个pair后,升序排序(先按第一维排序,若第一维相等,再按第二维排序),你能找到排序后的第k个元素吗?

 

Input

多组数据。

第一行,2个整数n和k (1<=n<=10000,1<=k<=n^2)。

第二行,n个整数,即原数组a1~an(1<=ai<=1000000000)。

 

Output

对于每组数据,输出两个整数,排序后的第k个pair。

 

Sample Input

2 4 2 1 3 2 3 1 5

Sample Output

2 2 1 3

HINT

题解:水

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)
const int MAXN=10010;
int m[MAXN];
int main(){
	int n,k;
	while(~scanf("%d%d",&n,&k)){
		for(int i=0;i<n;i++)SI(m[i]);
		sort(m,m+n);
		printf("%d %d\n",m[(k-1)/n],m[(k-1)%n]);
	}
	return 0;
}

Problem C: water problem II

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 80  Solved: 49
Submit Status Web Board

Description

相信大家对A+B问题最熟悉了。

实验室有个女人(传说中的潘同学)经常卡在这种题目上。。。

有一次,他边敷着面膜边做题,遇见了这样一个题目:

输入两个表示数的英文单词,输出他们的和。(当然输入的是英文,输出的是10进制数)

他头脑太ben了,想了半天没想出来怎么做?你能帮助他么?

 

Input

多组输入数据。每组数据输入两个表示数的英文单词(输入的数据是0-9)

 

Output

对于每组数据输出一个和。

 

Sample Input

one two

Sample Output

3
题解:a+b
代码:
#include<stdio.h>
#include<string.h>
int judge(char s[10])
{
	if(strcmp("zero",s)==0)return 0;
	if(strcmp(s,"one")==0)
	return 1;
	else if(strcmp(s,"two")==0)
	return 2;
		else if(strcmp(s,"three")==0)
	return 3;
		else if(strcmp(s,"four")==0)
	return 4;
		else if(strcmp(s,"five")==0)
	return 5;
		else if(strcmp(s,"six")==0)
	return 6;
		else if(strcmp(s,"seven")==0)
	return 7;
		else if(strcmp(s,"eight")==0)
	return 8;
		else if(strcmp(s,"nine")==0) return 9;
}
int main()
{
	int a,b;
	char s1[10],s2[10];
	while(scanf("%s%s",s1,s2)!=EOF)
	{
	
		a=judge(s1);
		b=judge(s2);
		printf("%d\n",a+b);
	}
	return 0;
}

  

Problem E: sort

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 125  Solved: 20
Submit Status Web Board

Description

想必大家对排序已经很熟悉了,但是spy好像对排序不太熟悉,有一天,他看到这样一个关于排序的题目:

对于 k 个用空格分隔开的整数,依次为 n1, n2 … nk。请将所有下标不能被 3 但可以被 2 整除的数在这些数字原有的位置上进行升序排列,此外,将余下下标能被 3 整除的数在这些数字原有的位置上进行降序排列。

spy想了半天不知道怎么排序,你可以帮助他么?

 

Input

多组数据,每组数据一行,为k个小于1000的正整数,依次为 n1, n2 … nk。(1 <= k <= 100000)

 

Output

对于每组数据,输出排序后的结果。

 

Sample Input

1 3 4 2 10 6 8

Sample Output

1 2 6 3 10 4 8

HINT

题解:暴力可以过;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)
const int MAXN=100010;
int m[MAXN],a[MAXN],b[MAXN];
int cmp(int a,int b){
	return a>b;
}
int main(){
	int k=0,k1=0,k2=0;
	char c;
	while(~scanf("%d",&m[k++])){
		c=getchar();
		if(c==' ')continue;
		else{
			for(int i=1;i<=k;i++){
				if(i%2==0&&i%3!=0)a[k1++]=m[i-1];
				else if(i%3==0)b[k2++]=m[i-1];
			}
			sort(a,a+k1);sort(b,b+k2,cmp);
			int flot=0;
			int a_i=0,b_i=0;
			for(int i=1;i<=k;i++){
				if(flot)P_;flot++;
				if(i%2==0&&i%3!=0)
					PI(a[a_i++]);
				else if(i%3==0)PI(b[b_i++]);
				else PI(m[i-1]);
			}
			puts("");
			k=0;k1=0;k2=0;
		}
	}
	return 0;
}

  

Problem H: easy problem

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 90  Solved: 43
Submit Status Web Board

Description

给你一个数字N,N的范围是1~1000000,求一个最小的正整数M,这个数字M的各个位的数字加上它本身之和恰好为N。当然,如果没有解,输出0。

 

Input

输入数据由多组数据组成,每行由一个数字N组成(1<=N<=1000000)。

 

Output

对于每组数据,输出仅一行包含一个整数M。如果对于每个N,存在最小的M,则输出这个最小值。如果不存在这个最小的M,则输出0。

 

Sample Input

216 121 2005

Sample Output

198 0 1979

HINT

题解:也是暴力,刚开始超时了几次,最后想想不需要从1开始,因为各个位数字只和肯定小于9*6;直接从N-9*6开始就好了;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)

int main(){
	int N;
	while(~scanf("%d",&N)){
		int flot=0;
		int x,temp;
		for(int i=N-60;i<=N;i++){
			x=i;temp=0;
			while(x){
				temp+=x%10;
				x/=10;
			}
			if(i+temp==N){
				printf("%d\n",i);
				flot=1;
				break;
			}
		}
		if(!flot){
			puts("0");
		}
	}
	return 0;
}

  

1817: match number

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 89  Solved: 39
Submit Status Web Board

Description

喜欢写程序的同学一般对数字较为敏感。对于一串长度为2*n的号码,我们认为如果它符合以下条件,就是匹配的:

把这个号码分为左右两半部分,长度均为n。对于左半部分的每一位数,右半部分都存在一位严格大于它的数;或者对于左半部分的每一位数,右半部分都存在一位严格小于它的数。注意,右半部分的每一位必须对应左半部分的某一位,也就是每一位数只能“使用”一次。

给出一个号码,你能判断它是否是匹配的吗?

 

Input

多组数据。

第一行,1个整数n(n<1000)。

第二行,一串长度为2*n的号码,由'0'~'9'组成。

 

Output

对于每组数据,如果号码是匹配的,输出"YES",否则输出"NO"(引号不输出)。

 

Sample Input

2 2421 2 0135 2 3754

Sample Output

YES YES NO

HINT

题解:不知道为啥要初始化,不初始化就会wa;

代码;

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)
const int MAXN=2020;
char s[MAXN];
int n;
/*int cmp(int a,int b){
	if(a<=b)return 1;
	else return 0;
}*/
int a[MAXN],b[MAXN];
bool js(int tf){
	//for(int i=0;i<n;i++)printf("%d",a[i]);puts("");
//	for(int i=0;i<n;i++)printf("%d",b[i]);puts("");
	if(tf){
		for(int i=0;i<n;i++){
			if(a[i]>=b[i])return false;
		}
		return true;
	}
	else{
		for(int i=0;i<n;i++){
			if(a[i]<=b[i])return false;
		}
		return true;
	}
}
int main(){
	while(~scanf("%d",&n)){
		mem(a,0);mem(b,0);
		scanf("%s",s);
		for(int i=0,j=n;i<n;i++,j++)a[i]=s[i]-'0',b[i]=s[j]-'0';
		sort(a,a+n);
		sort(b,b+n);
		int tf;
		if(a[0]<b[0])tf=1;
		else tf=0;
		if(js(tf))puts("YES");
		else puts("NO");
	}
	return 0;
}

  

1819: 加加加!(油)

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 59  Solved: 37
Submit Status Web Board

Description

实验室的小D同学又开始玩游戏了,这次他的游戏貌似很高级的样子。首先他在一张纸上写下了一个数n,然后他在两个无差别的球上写上两个数分别是a和b,他把两个球放在一个黑色的袋子中,然后他会从袋子中随机取出来一个球,并将这个n改变成n和这个球上标记的数的和。

是不是很简单!是不是很有意思!是不是很神奇!

(不是!)

好吧,这不是问题的所在,问题的所在是小d这个过程中n都有可能是些什么值。

 

Input

输入的第一行包含一个K,代表输入样例组数。

每组样例只有一行,包含四个整数"n a b m",n,a,b的含义为题目描述中的含义,m代表小D随机从袋子中取球的次数。(0 <= n < 1000000,0 <= a < 100000,0 <= b < 100000, 0 <=m < 10)

 

Output

把所有可能出现的n按照升序输出(不允许重复)。注意只有两个连续的数中间才允许空格,结尾不允许有空格。

 

Sample Input

3 1 1 1 1 4 2 3 2 5 100 102 1

Sample Output

1 2 4 6 7 8 9 10 5 105 107
暴力水过。。。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define P_ printf(" ")
#define T_T while(T--)
int c[2][5000],ans[5000];
int main(){
	int T,n,a,b,m;
	SI(T);
	T_T{
		scanf("%d%d%d%d",&n,&a,&b,&m);
		int cur=0;
		int k=0,pol=1;
		c[0][0]=n;
		ans[0]=n;
		while(m--){
			cur^=1;
			for(int i=0;i<pol;i++){
				c[cur][i<<1]=c[cur^1][i]+a;
				ans[++k]=c[cur][i<<1];
				c[cur][i<<1|1]=c[cur^1][i]+b;
				ans[++k]=c[cur][i<<1|1];
			}
			pol<<=1;
		}
		sort(ans,ans+k+1);
			k=unique(ans,ans+k+1)-ans;
		for(int i=0;i<k;i++){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}puts("");
	}
	return 0;
}

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值