资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

NEUQ2022第一次双周赛题解-创新互联

7-1 Lily

百合花(Lily)是一种美丽的花。她通常一年只开一次花,所以如果你看到百合花盛开,它会非常珍贵。然而,她对猫有剧毒,所以你必须注意让好奇的猫远离可爱的百合花。

创新互联-专业网站定制、快速模板网站建设、高性价比万山网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式万山网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖万山地区。费用合理售后完善,十余年实体公司更值得信赖。

你有n个网格的土壤土地排成一行,从1到n,其中一些是百合花。我们不想伤害百合,也不想伤害猫。你可以在网格上放一些猫粮,但对于任何有猫粮的网格i,在区域[i−1,i+1]不得含有百合花。你喜欢猫和百合,所以你想大限度地增加有猫粮的格子。

设计满足上述要求的计划。

输入格式:
有一个整数n(1≤n≤1000)表示网格的数量。

第二行包含仅由“L”和“.”组成的字符串R,表示有和没有百合花的格子。

输出格式:
输出包含一行,字符串R′仅由“L”、“”组成和“C”,其中“C”表示在满足上述要求的同时分配给R中空网格的猫粮。

输入样例:
在这里给出一组输入。例如:

5
..L..

输出样例:
在这里给出相应的输出。例如:

C.L.C
思路

二分答案,先二分出放猫粮的格子的数量,再验证放这么多数量的猫粮是否可行

代码
#includeusing namespace std;
int n;
char a[1010],b[1010];
void coutt()
{for (int i=1;i<=n;i++) cout<int cnt=0;
	for (int i=1;i<=n;i++) b[i]=a[i];
	for (int i=1;i<=n;i++) 
	{if (b[i+1]!='L'&&b[i-1]!='L'&&b[i]!='L')
		{	b[i]='C';
			cnt++;
		} 
		if (cnt>=k) return true; 
	}
	return false;
}
void half(int l,int r)
{while (l+1int mid=(l+r)/2;
		if (check(mid)==true) l=mid;
		else r=mid;
	} 
	if (check(r)==true) coutt();
	else 
	{check(l);
		coutt();
	}	
	return ;
} 
int main()
{cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	half(0,n);
	return 0;
}
7-2 a * b

给出两个不超过1000位的十六进制数a,b。
求a∗b的值

输入格式:
输入共两行,两个十六进制的数

输出格式:
输出一行,表示a∗b

输入样例:
在这里给出一组输入。例如:

1BF52
1D4B42

输出样例:
在这里给出相应的输出。例如:

332FCA5924
思路

考察进制转换和高精度乘法,先把输入的十六进制转换为十进制,再高精度乘法,最后输出

代码
#includeusing namespace std;
#define N 5010
int a[N],b[N],ans[N],l1,l2,l3=5000;
string s1,s2;
void trans(string s,int t[],int l)//将字符串s转换为数字存进t数组中 
{for (int i=1;i<=l;i++)
	{if (s[i-1]=='A') t[l-i+1]=10;
		else if (s[i-1]=='B') t[l-i+1]=11;
		else if (s[i-1]=='C') t[l-i+1]=12;
		else if (s[i-1]=='D') t[l-i+1]=13;
		else if (s[i-1]=='E') t[l-i+1]=14;
		else if (s[i-1]=='F') t[l-i+1]=15;
		else t[l-i+1]=s[i-1]-'0';
	}
	return;
}
void cheng(int a[],int b[])//高精度乘法 
{for (int i=1;i<=l1;i++)
	  for (int j=1;j<=l2;j++)
	  {  	  ans[i+j-1]+=a[i]*b[j];
	  	  ans[i+j]+=ans[i+j-1]/16;
	  	  ans[i+j-1]%=16;
	  }
	while (ans[l3]==0) 
	  l3--;
	return;
}
void ccout()
{for (int i=l3;i>=1;i--)
	{if (ans[i]==10) cout<<"A";
		else if (ans[i]==11) cout<<"B";
		else if (ans[i]==12) cout<<"C";
		else if (ans[i]==13) cout<<"D";
		else if (ans[i]==14) cout<<"E";
		else if (ans[i]==15) cout<<"F";
		else cout<cin>>s1>>s2;
	l1=s1.length();
	l2=s2.length();
	l3=5000;
	trans(s1,a,l1);
	trans(s2,b,l2);
	//for (int i=1;i<=l2;i++) cout<
7-3 山头狙击战

题目描述
小明为了掩护大部队,单枪匹马同敌人周旋,后来被敌人包围在某山头……等等,为什么怎么听怎么像狼牙山五壮士!不过不用着急,这次小明携带了足够的弹药,完全可以将涌上来的敌人一个一个干掉。小明是个神枪手,只要他的枪膛中有子弹,他就能将在他射程m(用从敌人位置到山头的直线距离算)以内的一个敌人瞬间射杀。但如果在射程内没有敌人,出于节约子弹考虑和面子问题,小明会等待敌人靠近然后射击。
正当小明为自己的强大而自我膨胀时,他忽然发现了一个致命的失误:他携带的枪是单发枪,每射出一发子弹都必须花k秒钟的时间装子弹。而凶残的敌人才不会花时间等你换子弹呢。他们始终在以1m/s的速度接近山头。而如果在一个敌人到达山头时小明无法将他击毙,那么我们可怜的小明就将牺牲在敌人的刺刀下。现在小明用心灵感应向你发出求助:要保住自己的性命并且歼灭所有敌人,小明最多只能用多少时间给枪装上一发子弹?
说明:假设一开始小明的枪中就有一发子弹,并且一旦确定一个装弹时间,小明始终会用这个时间完成子弹的装卸。希望你能帮助小明脱离险境。

输入格式
每组输入数据,第一行有两个整数n和m,(2≤n≤100,000; 1≤m≤10,000,000)n代表敌人个数,m代表小明的射程。
接下来有n行,每行一个整数mi,(1≤mi≤10,000,000),代表每个敌人一开始相对山头的距离(单位为米)。

输出格式
每组输出数据仅有一个整数,代表小明的换弹时间(单位为秒)。

样例输入

6 100
236
120
120
120
120
120

样例输出

25
思路

用二分答案寻找最佳换弹时间,check()函数检查当前二分的换弹时间能否全部击中敌人

#includeusing namespace std;
#define N 100010
int n,m,a[N];
bool check(int k)
{int t=max(0,a[1]-m);//t:时间
	for (int i=2;i<=n;i++)
	{t+=k;//装填子弹
		if (a[i]while (l+1int mid=(l+r)/2;
		if (check(mid)==true) l=mid;
		else r=mid;
	}
	if (check(r)==true) return r;
	else return l;
}
int main()
{cin>>n>>m;
	for (int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	cout<
7-4 Reversing Linked List

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.

Input Specification:
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤10
5
) which is the total number of nodes, and a positive K (≤N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Data Next
where Address is the position of the node, Data is an integer, and Next is the position of the next node.

Output Specification:
For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218

Sample Output:

00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1
思路

用数组模拟链表

#includeusing namespace std;
#define N 1000010
int st,ed,n,m,temp,id[N],nnext[N],llist[N];
int main()
{cin>>st>>n>>m;
    for (int i=1;i<=n;i++)
    {cin>>temp;
        cin>>id[temp]>>nnext[temp];
    }
    int cnt=0,now=st;        
    while (now!=-1) 
    {cnt++;
        llist[cnt]=now; 
        now=nnext[now];
        //list[i]=nnext[list[i-1]]
    }
    for (int i=1;i<=(cnt-cnt%m);i+=m) 
	{//if (i+m>n) break;
		reverse(llist+i,llist+i+m);
	}
    for (int i=1;i<=cnt-1;i++) printf("%05d %d %05d\n",llist[i],id[llist[i]],llist[i+1]);
    printf("%05d %d -1",llist[cnt],id[llist[cnt]]);
	return 0;
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


文章标题:NEUQ2022第一次双周赛题解-创新互联
网站地址:http://cdkjz.cn/article/pcjgp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220