HUST 新人个人赛 7.23

吃喝等死的节奏.......

早起看hust oj上有练习

就等到九点开始做

第一题一看是简单贪心..后来发现数据量太大果断不会做...搜题解说是dp+线段树..ORZ..我线段树只会敲基本的...这题果断放弃了..

B - EZAC II
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

An alternative formula for the Fibonacci sequence is

.

Given an integer n, your goal is to compute the last 4 digits of Fn.

Input

The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.

Output

For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).

Sample Input

0
9
999999999
1000000000
-1

Sample Output

0
34
626
6875

Hint

As a reminder, matrix multiplication is associative, and the product of two 2 × 2 matrices is given by

.

Also, note that raising any 2 × 2 matrix to the 0th power gives the identity matrix:

.


裸的矩阵快速幂,即使我不会写矩阵快速幂

翻书搜模版

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct matrix
{
	int mat[2][2];
};
matrix start;
int n=2,mod=10000;
matrix mul(matrix a,matrix b)
{
	matrix temp;
	memset(temp.mat,0,sizeof(temp.mat));
	for(int i=0;i<n;i++)
	{
		for(int k=0;k<n;k++)
		{
			if(a.mat[i][k])
			{
				for(int j=0;j<n;j++)
				{
					temp.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
					if(temp.mat[i][j]>=mod)
					{
						temp.mat[i][j]%=mod;
					}
				}
			}
		}
	}
	return temp;
}
matrix expo(matrix p,int k)
{
	if(k==1)
	{
		return p;
	}
	matrix temp;
	memset(temp.mat,0,sizeof(temp.mat));
	for(int i=0;i<n;i++)
	{
		temp.mat[i][i]=1;
	}
	if(k==0)
	{
		return temp;
	}
	while(k)
	{
		if(k%2)
		{
			temp=mul(p,temp);
		}
		p=mul(p,p);
		k/=2;
	}
	return temp;
}
int main()
{
	start.mat[1][1]=0;
	start.mat[1][0]=start.mat[0][1]=start.mat[0][0]=1;
	int k;
	while(cin>>k&&k!=-1)
	{
		cout<<expo(start,k).mat[0][1]%mod<<endl;
	}
	return 0;
}
		
		

C - EZAC III
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

windy定义了一种windy数。
不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。
windy想知道,在A和B之间,包括A和B,总共有多少个windy数?

Input

包含两个整数,A B。
满足 1 <= A <= B <= 2000000000 。

Output

包含一个整数:闭区间[A,B]上windy数的个数。

Sample Input

1 10

Sample Output

9


数位dp,一个周前练习过

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int dp[25][15][2];
int bit[25]; 
//dp[pos][pre][have]
//pos当前位置
//pre之前已经确定的部分
//have 前面是否全为0 1:不是全为0 0:全为0 
int dfs(int pos,int pre,int have,int doing)
{
	if(pos==-1)
	{
		if(have)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	if(!doing&&dp[pos][pre][have]!=-1)
	{
		return dp[pos][pre][have];
	}
	int ans=0;
	int end=doing?bit[pos]:9;
	for(int i=0;i<=end;i++)
	{
		int nhave=have;
		if(have==0)
		{
			if(i==0)
			{
				nhave=0;
			}
			else
			{
				nhave=1;
			}
			ans+=dfs(pos-1,i,nhave,doing&&i==end);
		}
		else if(abs(i-pre)>=2)
		{
			nhave=1;
			ans+=dfs(pos-1,i,nhave,doing&&i==end);
		}
	//	ans+=dfs(pos-1,i,nhave,doing&&i==end);
	}
	if(!doing)
	{
		dp[pos][pre][have]=ans;
	}
	return ans;
}
int solve(int n)
{
	int len=0;
	while(n)
	{
		bit[len++]=n%10;
		n/=10;
	}
	return dfs(len-1,0,0,1);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	int a,b;
	while(cin>>a>>b)
	{
		cout<<solve(b)-solve(a-1)<<endl;
	}
	return 0;
}

D - EZAC IV
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be

.

Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores.

Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is . However, if you drop the third test, your cumulative average becomes .

Input

The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for all i. The third line contains n positive integers indicating bi for all i. It is guaranteed that 0 ≤ ai ≤ bi ≤ 1, 000, 000, 000. The end-of-file is marked by a test case with n = k = 0 and should not be processed.

Output

For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer.

Sample Input

3 1
5 0 2
5 1 6
4 2
1 2 7 9
5 6 7 9
0 0

Sample Output

83
100

Hint

To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).


公式推导一下发现是二分题

题解参照这个链接

/*
http://www.baidu.com/link?url=LyMVYeWhyhNXE_R99qXp-BABjdLKTH9Cf_rpUhSMu_901x9tZWR74YxAsaKmGb3f0sbZIUy1JWNdjacXaDG-uNQy25OKnK1zupKhRmgLqG3
*/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define MIN 1e-6
using namespace std;
int n,k;
double a[1005];
double b[1005];
double value[1005];
int main()
{
	while(cin>>n>>k,n!=0||k!=0)
	{
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(int j=0;j<n;j++)
		{
			cin>>b[j];
		}
		double left=0;
		double right=100;
		double mid;
		while(right-left>MIN)
		{
			mid=(left+right)/2;
			for(int i=0;i<n;i++)
			{
				value[i]=100*a[i]-mid*b[i];
			}
			sort(value,value+n);
			double sum=0;
			for(int i=k;i<n;i++)
			{
				sum+=value[i];
			}
			if(sum>0)
			{
				left=mid;
			}
			else
			{
				right=mid;
			}
		}
		printf("%.0lf\n",left);
	}
	return 0;
}

E - EZAC V
Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N). 

We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2), we change all the elements in the rectangle by using "not" operation (if it is a '0' then change it into '1' otherwise change it into '0'). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions. 

1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= n, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2). 
2. Q x y (1 <= x, y <= n) querys A[x, y]. 

Input

The first line of the input is an integer X (X <= 10) representing the number of test cases. The following X blocks each represents a test case. 

The first line of each block contains two numbers N and T (2 <= N <= 1000, 1 <= T <= 50000) representing the size of the matrix and the number of the instructions. The following T lines each represents an instruction having the format "Q x y" or "C x1 y1 x2 y2", which has been described above. 

Output

For each querying output one line, which has an integer representing A[x, y]. 

There is a blank line between every two continuous test cases. 

Sample Input

1
2 10
C 2 1 2 2
Q 2 2
C 2 1 2 1
Q 1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
Q 1 1
C 1 1 2 1
Q 2 1

Sample Output

1
0
0
1

二维树状数组,还是翻书敲模版...

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n;
int c[1005][1005];
int lowbit(int x)
{
	return x&(-x);
}
void update(int i,int j,int k)
{
	while(i<=n)
	{
		int temp=j;
		while(temp<=n)
		{
			c[i][temp]+=k;
			temp+=lowbit(temp);
		}
		i+=lowbit(i);
	}
}
int sum(int i,int j)
{
	int sum=0;
	while(i>0)
	{
		int temp=j;
		while(temp>0)
		{
			sum+=c[i][temp];
			temp-=lowbit(temp);
		}
		i-=lowbit(i);
	}
	return sum;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		memset(c,0,sizeof(c));
		int t;
		cin>>n>>t;
		while(t--)
		{
			char s[5];
			cin>>s;
			if(s[0]=='C')
			{
				int x1,y1,x2,y2;
				cin>>x1>>y1>>x2>>y2;
				x2++;
				y2++;
				update(x1,y1,1);
				update(x1,y2,-1);
				update(x2,y1,-1);
				update(x2,y2,1);
			}
			else
			{
				int x1,y1;
				cin>>x1>>y1;
				cout<<sum(x1,y1)%2<<endl;
			}
		}
		cout<<endl;
	}
	return 0;
}
				

今天下午的训练

自己先做好辅助

记录下不会的题目与知识点

利用训练间隙补上

以上.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值