寒假集训个人赛div.2题解

打得不好,虽然最后rank6,但是B题现场学结构体排序真的醉了,所以基础真的很重要
A Let sudoku rotate
Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the world.

In this problem, let us focus on puzzles with 16×16 grids, which consist of 4×4 regions. The objective is to fill the whole grid with hexadecimal digits, i.e. 0123456789ABCDEF, so that each column, each row, and each region contains all hexadecimal digits. The figure below shows a solved sudoku.

在这里插入图片描述
Yesterday, Kazari solved a sudoku and left it on the desk. However, Minato played a joke with her - he performed the following operation several times.

  • Choose a region and rotate it by 90 degrees counterclockwise.

She burst into tears as soon as she found the sudoku was broken because of rotations.

Could you let her know how many operations her brother performed at least?
Input
The first line of the input contains an integer TT (1≤T≤10^3)denoting the number of test cases.

Each test case consists of exactly 1616 lines with 1616 characters each, describing a broken sudoku.

	Output

For each test case, print a non-negative integer indicating the minimum possible number of operations.

	Sample Input 1

681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63
39FAED5616400B74
D120C4B7CA3DEF38
7EC829A085BE6D51
B56438F129F79C2A
5C7FBC4E3D08719F
AE8B1673BF42A58D
60D3AF25619C30BE
294190D8EA57264C
C7D1B35606835EAB
AF52A1E019BE4306
8B36DC78D425F7C9
E409492FC7FA18D2

Sample Output
5
被题目吓傻了,没敢开,后来发现就是个dfs加剪枝,不过要码很多,一百多行吧QAQ(像我这种手残党还好没开)
代码还没写,打算找个良辰吉日补上(绝对不是因为懒)

B Buildings
Description
  Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building.

The public opinion is that Guanghua Building is nothing more than one of hundreds of modern skyscrapers recently built in Shanghai, and sadly, they are all wrong. Blue.Mary the great civil engineer had try a completely new evolutionary building method in project of Guanghua Building. That is, to build all the floors at first, then stack them up forming a complete building.

Believe it or not, he did it (in secret manner). Now you are face the same problem Blue.Mary once stuck in: Place floors in a good way.

Each floor has its own weight wi and strength si. When floors are stacked up, each floor has PDV(Potential Damage Value) equal to (Σwj)-si, where (Σwj) stands for sum of weight of all floors above.

Blue.Mary, the great civil engineer, would like to minimize PDV of the whole building, denoted as the largest PDV of all floors.

Now, it’s up to you to calculate this value.

	Input

There’re several test cases.

In each test case, in the first line is a single integer N (1 <= N <= 10
5) denoting the number of building’s floors. The following N lines specify the floors. Each of them contains two integers wi and si (0 <=wi, si <= 100000) separated by single spaces.

Please process until EOF (End Of File).

	Output

For each test case, your program should output a single integer in a single line - the minimal PDV of the whole building.

If no floor would be damaged in a optimal configuration (that is, minimal PDV is non-positive) you should output 0.

	Sample Input 3

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

	Sample Output 
	1
	0
	2 

题目的表述真的有点东西,这一段愣是看了好几遍才看懂would like to minimize PDV of the whole building, denoted as the largest PDV of all floors,原来是将楼层最大的PDV作为整栋楼最小的PDV。
这种问题很容易想到贪心,考虑两组(wi,si),(wj,sj),不妨令wi-sj>wj-si,
即wi+si的和越小的应该放在越上面,所以就有了:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;//现场学结构体,我要凉了 
struct x{	
	int w,s;
}gg[100005];
long long maxpdv;
long long sumw[100005];
bool cmp(x a,x b){
	return (a.w+a.s)<b.w+b.s;
}
int main(){
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++) scanf("%d %d",&gg[i].w,&gg[i].s);
		sort(gg,gg+n,cmp);
		sumw[0]=gg[0].w;
		maxpdv=gg[0].w-gg[1].s;
		for(i=1;i<n-1;i++){
			sumw[i]=sumw[i-1]+gg[i].w;
			//maxpdv=max(maxpdv,sumw[i]-gg[i+1].s);
			if(sumw[i]-gg[i+1].s>maxpdv) maxpdv=sumw[i]-gg[i+1].s;
		}
		if(maxpdv>0) printf("%I64d\n",maxpdv);
		else printf("0\n");
	}
	return 0;
}

C River Hopscotch
Description
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N).
FJ wants to know exactly how much he can increase the shortest distance before he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.

	Input

Line 1: Three space-separated integers:
L,
N, and
M

Lines 2…
N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.

	Output

Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing
M rocks

	Sample Input
	25 5 2
	2
	14
	11
	21
	17
	Sample Output
	4

Hint
Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
题目情景无力吐槽,当时居然没看懂QAQ,主要是跟生活常识差的太多了,啥人会无聊到比赛母牛跳河,而且母牛还贼六,什么距离都能跳,然后问拿掉m块石头后母牛能跳的最短距离,数据很大,暴力枚举会凉,所以就二分吧,感觉写起来就是一个二分的板子题,首先距离是线性的,所以通过二分来枚举距离,对于每个区间计算中点再判断

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int l,m,n,a[50001];
bool fun(int mid){
	int i,start=0,x=0;
	for(i=1;i<=n;i++){
		if(a[i]-start<mid)
			x++;
		else 
			start=a[i];
	}
	if(l-start<mid) return false;//最后一跳如果小于mid,说明最短长度要更小
	if(x>m) return false;
	return true;
}
int main(){
	int i;
	while(scanf("%d %d %d",&l,&n,&m)!=EOF){
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a,a+n+1);
		int left=0,right=l,mid,ans;
		while(right>=left){
			mid=left+(right-left)/2;
			if(fun(mid)){
				left=mid+1;
				ans=mid;
			}
			else {
				right=mid-1;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

D so Easy!
A sequence Sn is defined as:
在这里插入图片描述
Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
You, a top coder, say: So easy!
Input
  There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 2^15,
(a-1)^2< b <
a^2, 0 < b,
n < 2^31.The input will finish with the end of file.

	Output

For each the case, output an integer S
n.

	Sample Input 2 3 1 2013

2 3 2 2013
2 2 1 2013

	Sample Output 4

14
4

一点都不Easy。刚开始用快速幂写了一发交了一发,以为数据很水,结果是我太天真了,然后仔细想想,仔细读题,发现b>(a-1)^2这个关键条件,显然对于
(a+√b)^n可以写成Xn+Yn√b的形式
(a-√b)^n可以写为Xn-Yn
√b的形式,这里的
(a-√b)^n<1,
所以[(a+√b)^n+
(a-√b)^n]=
[ (a+√b)^n]=2Xn
容易得出,Xn=a
Xn-1+bYn-1,Yn=Xn-1+aYn-1,那么构造矩阵A,使得(Xn-1,Yn-1)*A=(Xn,Yn),显然,A=|a 1|
|b a|.
由于X0=1,Y0=0,所以(Xn,Yn)=(1 0)A^n.
那么就可以愉快地敲矩阵乘法和矩阵快速幂的板子来AC啦。
以上方法是我认为比较简单的方法了,当然如果你能看出
Sn+1=2a
Sn−(a^2−b)*Sn−1,就当我没说QAQ。这个递推的证明很简单,读者不妨自己试试,只是想到这个递推很难很难(能想到估计高中
是CMO的银牌以上了吧),那么上代码:

#include<stdio.h>
#include<math.h>
typedef long long ll;
struct matrix{
 ll mm[2][2];
};
int n,m;
matrix multi(matrix x,matrix y){
 matrix temp;int i,j,k;
 for(i=0;i<2;i++){
  for(j=0;j<2;j++){
   temp.mm[i][j]=0;
   for(k=0;k<2;k++) temp.mm[i][j]=(temp.mm[i][j]+x.mm[i][k]*y.mm[k][j])%m;
  }
 }
 return temp;
}
ll qpow_ans(matrix a,int n){
 matrix b;
 b.mm[0][0]=b.mm[1][1]=1;
 b.mm[0][1]=b.mm[1][0]=0;
 /*for(int i=0;i<2;i++){
  for(int j=0;j<2;j++) printf("a.mm[%d][%d]=%I64d ",i,j,a.mm[i][j]);
  printf("\n");
 }*/
 while(n){
  if(n&1) b=multi(b,a);
  a=multi(a,a);
  n>>=1;
 }
 return 2*b.mm[0][0]%m;
}
int main(){
 int aa,bb;
 while(scanf("%d %d %d %d",&aa,&bb,&n,&m)!=EOF){
  matrix ans;
  ans.mm[0][0]=aa;ans.mm[0][1]=1;
  ans.mm[1][0]=bb;ans.mm[1][1]=aa;
  ll answer=qpow_ans(ans,n);
  printf("%lld\n",answer);
 }
 return 0;
}

未完待续

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值