冲击省赛(还有6天)

(第一题 A+B Problem)

原题连接:Problem - 6938 (hdu.edu.cn)

HZ has a special calculator, in which all the integers are 11-bit signed integers. The range of an 11-bit signed integer is from −210 to 210−1 (from −1024 to 1023). When using this calculator to calculate the sum of two integers A and B, the result may be different from other calculators. Here are some examples:

1+1=2

1023+1=-1024

1023+2=-1023

-1024+(-1)=1023

-1024+(-2)=1022

HZ found this special calculator very strange, so he comes to you. You are given two integers A and B, and you need to guess the result of A+B of this calculator.

Input

The first line of input contains an integer T (1≤T≤105), denoting the number of test cases.

Each test case contains two integers A and B in one line. −1024≤A,B≤1023.

Output

For each test case, print one integer in one line, denoting your answer.

Sample Input

5
1 1
1023 1
1023 2
-1024 -1
-1024 -2

Sample Output

2
-1024
-1023
1023
1022

(签到题,找规律)

#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+7;
int a[N];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        if(n+m>=-1024&&n+m<=1023)cout<<n+m<<endl;
        else{
        	if(n+m>1023){
        		cout<<-1024+(n+m-1024)<<endl;
			}
			else{
				cout<<1023+(1025+(n+m))<<endl; 
			}
		}
    }
}

(第二题 Game)

原题连接:Problem - 6944 (hdu.edu.cn)

目前还没做出来

(第三题  Stacks)

原题连接:Problem - 6947 (hdu.edu.cn)

目前还做出来

(第四题  打开所有的灯)

原题连接:P2040 打开所有的灯 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

题目背景

pmshz在玩一个益(ruo)智(zhi)的小游戏,目的是打开九盏灯所有的灯,这样的游戏难倒了pmshz。。。

题目描述

这个灯很奇(fan)怪(ren),点一下就会将这个灯和其周围四盏灯的开关状态全部改变。现在你的任务就是就是告诉pmshz要全部打开这些灯。

例如

0  1  1
1  0  0
1  0  1

点一下最中间的灯【2,2】就变成了

0  0  1
0  1  1
1  1  1

再点一下左上角的灯【1,1】就变成了

1  1  1
1  1  1
1  1  1

达成目标。最少需要2步。

输出2即可。

输入格式

九个数字,3*3的格式输入,每两个数字中间只有一个空格,表示灯初始的开关状态。(0表示关,1表示开)

输出格式

1个整数,表示最少打开所有灯所需要的步数。

输入输出样例

输入 #1复制

 

0 1 1
1 0 0
1 0 1

输出 #1复制

2

说明/提示

这个题水不水,就看你怎么考虑了。。。。

思路:这题bfs和dfs都能做,起初我想的简便方法,想着固定第一行算一遍,和最后一行再算一遍找个最小值,最终wa了,他后面改变也会影响前面

现在提供一个dfs,这个代码看过别人思路的0.0本人比较菜,这个思路就是递归遍历每一个点,然后改变开关,最主要的是每个点最多被遍历一次,当重复遍历后相当于没有改变

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const int N=11;
int a[N][N],b[N],s[N];
bool st[N];
int res=10,ans=0;
//改变灯
void change(int x,int y){
	a[x][y]=1-a[x][y];
	a[x-1][y]=1-a[x-1][y];
	a[x+1][y]=1-a[x+1][y];
	a[x][y-1]=1-a[x][y-1];
	a[x][y+1]=1-a[x][y+1];
} 
void dfs(int k){
	if(k>res)return ;//
	int sum=0;//计算1的个数 
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			sum+=a[i][j];
		}
	}
	if(sum==9){
		ans=k-1;
		if(ans<res)res=ans;
	//	res=min(res,k-1);//找到答案,但是是传过来的前一步 
	} 
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			change(i,j);//改变开关 
			dfs(k+1);
			change(i,j);//回溯 
		}
	} 
	return ; 
}

int main(){
	 for(int i=1;i<=3;i++)
	 	for(int j=1;j<=3;j++)
	 		cin>>a[i][j];
	 dfs(1);
	 cout<<res;
}

(第五题  Getting Zero)

原题连接:Problem - 1661B - Codeforces

Suppose you have an integer v. In one operation, you can:

either set v=(v+1)mod32768
or set v=(2⋅v)mod32768.
You are given nn integers a1,a2,…,an. What is the minimum number of operations you need to make each aiai equal to 00?

Input
The first line contains the single integer n (1≤n≤32768) — the number of integers.

The second line contains nn integersa1,a2,…,an (0≤ai<32768).

Output
Print n integers. The ii-th integer should be equal to the minimum number of operations required to make aiai equal to 0.

Example
inputCopy

4
19 32764 10240 49


outputCopy

14 4 4 15 


Note
Let's consider each ai:

a1=19. You can, firstly, increase it by one to get 2020 and then multiply it by two 13 times. You'll get 0 in 1+13=14 steps.
a2=32764. You can increase it by one 4 times: 32764→32765→32766→32767→032764→32765→32766→32767→0.
a3=10240. You can multiply it by two 4 times: 10240→20480→8192→16384→010240→20480→8192→16384→0.
a4=49. You can multiply it by two 15 times.

出题人定义为dp,我还没来得及去写dp题解,我先讲我当时的思路

思路一:首先我们可以发现2^15=32768,所有我们可以根据根据奇数和偶数划分

偶数:

1,如果当前是2的n次方就可以直接判断32768-v和15-n的大小,输出最小的,

因为他就要么一直乘以二,要么他离32768非常近(可能不用判断32768-v我下去想想)

2,如果当前不是2的多少次方,我想的首先找到他包含2的n次方,在进行1到15-n依次加 1

如果存在比当前的偶数更好的数就加上去,例如14,他加2到16花费2,你却可以得到4,而原值14

他只含一个2,没有现在的数好

奇数:更偶数想法一样,将该值加一就是偶数了,后面操跟偶数一样的思路

可以将中间相同的部分写成函数

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=32768;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		int num=0;
		cin>>x;
		if(x==0)cout<<0<<endl;
		else{
			if(x%2==0){
				int y=x;
				int sum=0;
				while(y%2==0){
					sum++;
					y/=2;
				}
				if(pow(2,sum)==x){
					int m=N-x;
					if(m<15-sum)cout<<m<<endl;
					else{
						cout<<15-sum<<endl;
					} 
				}
				else{
					int indx=0;
					for(int i=1;i<=15;i++){
						int s=x+i;
						int sum1=0,m1=0;
						while(s%2==0){
							sum1++;
							s/=2;
						}
						if(sum1-sum>i){
							sum=sum1;
							indx=i;
						}
					}
					int m=N-x+indx;
					
					if(m<15-sum)cout<<m<<endl;
					else{
						cout<<15-sum+indx<<endl;
					} 
				}
				
			}
			else{
				x++;
				int y=x;
				int sum=0;
				while(y%2==0){
					sum++;
					y/=2;
				}
				if(pow(2,sum)==x){
					int m=N-x;
					if(m<15-sum)cout<<m+1<<endl;
					else{
						cout<<15-sum+1<<endl;
					} 
				}
				else{
					int indx=0;
					for(int i=1;i<=15;i++){
						int s=x+i;
						int sum1=0,m1=0;
						while(s%2==0){
							sum1++;
							s/=2;
						}
						if(sum1-sum>i){
							sum=sum1;
							indx=i;
						}
					}
					int m=N-x+indx;
					
					if(m<15-sum)cout<<m+1<<endl;
					else{
						cout<<15-sum+indx+1<<endl;
					} 
				}
				
			}
		}
	}
}

dp代码后面写上去

(第六题 Nastia and a Good Array )

原题连接:Problem - 1521B - Codeforces

未写出来,后续....

Nastia has received an array of n positive integers as a gift.

She calls such an array aa good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers uu and vv.

You can perform the operation: select two different indices i,ji,j (1≤i,j≤n, ii≠j) and two integers xx,y (1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y). Then change ai to x and aj to yy.

The girl asks you to make the array good using at most nn operations.

It can be proven that this is always possible.

Input
The first line contains a single integer tt (1≤t≤10000) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤105) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,an (1≤ai≤1091≤ai≤109) — the array which Nastia has received as a gift.

It's guaranteed that the sum of nn in one test doesn't exceed 2⋅105.

Output
For each of tt test cases print a single integer kk (0≤k≤n0≤k≤n) — the number of operations. You don't need to minimize this number.

In each of the next kk lines print 4 integers i, j, x, y (1≤i≠j≤n, 1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y) — in this manner you replace aiai with xx and ajaj with yy.

If there are multiple answers, print any.

Example
inputCopy
2
5
9 6 3 11 15
3
7 5 13
outputCopy
2
1 5 11 9
2 5 7 6
0
Note
Consider the first test case.

Initially a=[9,6,3,11,15]a=[9,6,3,11,15].

In the first operation replace a1a1 with 1111 and a5a5 with 99. It's valid, because min(a1,a5)=min(11,9)=9.

After this a=[11,6,3,11,9].

In the second operation replace a2a2 with 77 and a5a5 with 66. It's valid, because min(a2,a5)=min(7,6)=6.

After thisa=[11,7,3,11,6] — a good array.

In the second test case, the initial array is already good.

(第七题 分糖果)

原题连接:P7909 [CSP-J 2021] 分糖果 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

题目背景

红太阳幼儿园的小朋友们开始分糖果啦!

题目描述

红太阳幼儿园有 nn 个小朋友,你是其中之一。保证 n \ge 2n≥2。

有一天你在幼儿园的后花园里发现无穷多颗糖果,你打算拿一些糖果回去分给幼儿园的小朋友们。

由于你只是个平平无奇的幼儿园小朋友,所以你的体力有限,至多只能拿 RR 块糖回去。

但是拿的太少不够分的,所以你至少要拿 LL 块糖回去。保证 n \le L \le Rn≤L≤R。

也就是说,如果你拿了 kk 块糖,那么你需要保证 L \le k \le RL≤k≤R。

如果你拿了 kk 块糖,你将把这 kk 块糖放到篮子里,并要求大家按照如下方案分糖果:只要篮子里有不少于 nn 块糖果,幼儿园的所有 nn 个小朋友(包括你自己)都从篮子中拿走恰好一块糖,直到篮子里的糖数量少于 nn 块。此时篮子里剩余的糖果均归你所有——这些糖果是作为你搬糖果的奖励

作为幼儿园高质量小朋友,你希望让作为你搬糖果的奖励的糖果数量(而不是你最后获得的总糖果数量!)尽可能多;因此你需要写一个程序,依次输入 n, L, Rn,L,R,并输出你最多能获得多少作为你搬糖果的奖励的糖果数量。

输入格式

输入一行,包含三个正整数 n, L, Rn,L,R,分别表示小朋友的个数、糖果数量的下界和上界。

输出格式

输出一行一个整数,表示你最多能获得的作为你搬糖果的奖励的糖果数量。

输入输出样例

输入

7 16 23

输出

6

其他样例看连接

思路:签到题 +找找规律

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+7;
int a[N];
int main(){
    int t;
    //cin>>t;
    t=1;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        int x=l%n;
        int y=r-l;
        if(x+y>=n){
        	cout<<n-1;
		}
		else{
			cout<<x+y;
		}
    }
}

(第八题  蚯蚓)

原题连接:P2827 [NOIP2016 提高组] 蚯蚓 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

题目描述

本题中,我们将用符号 \lfloor c \rfloor⌊c⌋ 表示对 cc 向下取整,例如:\lfloor 3.0 \rfloor = \lfloor 3.1 \rfloor = \lfloor 3.9 \rfloor = 3⌊3.0⌋=⌊3.1⌋=⌊3.9⌋=3。

蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓。

蛐蛐国里现在共有 nn 只蚯蚓(nn 为正整数)。每只蚯蚓拥有长度,我们设第 ii 只蚯蚓的长度为 a_iai​ (i=1,2,\dots,ni=1,2,…,n),并保证所有的长度都是非负整数(即:可能存在长度为 00 的蚯蚓)。

每一秒,神刀手会在所有的蚯蚓中,准确地找到最长的那一只(如有多个则任选一个)将其切成两半。神刀手切开蚯蚓的位置由常数 pp(是满足 0 < p < 10<p<1 的有理数)决定,设这只蚯蚓长度为 xx,神刀手会将其切成两只长度分别为 \lfloor px \rfloor⌊px⌋ 和 x - \lfloor px \rfloorx−⌊px⌋ 的蚯蚓。特殊地,如果这两个数的其中一个等于 00,则这个长度为 00 的蚯蚓也会被保留。此外,除了刚刚产生的两只新蚯蚓,其余蚯蚓的长度都会增加 qq(是一个非负整常数)。

蛐蛐国王知道这样不是长久之计,因为蚯蚓不仅会越来越多,还会越来越长。蛐蛐国王决定求助于一位有着洪荒之力的神秘人物,但是救兵还需要 mm 秒才能到来……(mm 为非负整数)

蛐蛐国王希望知道这 mm 秒内的战况。具体来说,他希望知道:

  • mm 秒内,每一秒被切断的蚯蚓被切断前的长度(有 mm 个数);
  • mm 秒后,所有蚯蚓的长度(有 n + mn+m 个数)。

蛐蛐国王当然知道怎么做啦!但是他想考考你……

输入格式

第一行包含六个整数 n,m,q,u,v,tn,m,q,u,v,t,其中:n,m,qn,m,q 的意义见【问题描述】;u,v,tu,v,t 均为正整数;你需要自己计算 p=u / vp=u/v(保证 0 < u < v0<u<v);tt 是输出参数,其含义将会在【输出格式】中解释。

第二行包含 nn 个非负整数,为 a_1, a_2, \dots, a_na1​,a2​,…,an​,即初始时 nn 只蚯蚓的长度。

同一行中相邻的两个数之间,恰好用一个空格隔开。

保证 1 \leq n \leq 10^51≤n≤105,0 \leq m \leq 7 \times 10^60≤m≤7×106,0 < u < v \leq 10^90<u<v≤109,0 \leq q \leq 2000≤q≤200,1 \leq t \leq 711≤t≤71,0 \leq a_i \leq 10^80≤ai​≤108。

输出格式

第一行输出 \left \lfloor \frac{m}{t} \right \rfloor⌊tm​⌋ 个整数,按时间顺序,依次输出第 tt 秒,第 2t2t 秒,第 3t3t 秒,……被切断蚯蚓(在被切断前)的长度。

第二行输出 \left \lfloor \frac{n+m}{t} \right \rfloor⌊tn+m​⌋ 个整数,输出 mm 秒后蚯蚓的长度;需要按从大到小的顺序,依次输出排名第 tt,第 2t2t,第 3t3t,……的长度。

同一行中相邻的两个数之间,恰好用一个空格隔开。即使某一行没有任何数需要输出,你也应输出一个空行。

请阅读样例来更好地理解这个格式。

输入输出样例

输入

3 7 1 1 3 1
3 3 2

输出

3 4 4 4 5 5 6
6 6 6 5 5 4 4 3 2 2

字太多了当时没有读完0.0后续跟新

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linkk_bug

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值