哈尔滨工程大学ACM预热赛 补题
链接:https://ac.nowcoder.com/acm/contest/554/A
来源:牛客网
大虎是学校信息学集训队的,立刻想到用计算机来解决这个问题,并很快有了解答:13。第二天他把问题拿到了学校,
数据范围
30%数据:1≤N≤12
50%数据:1≤N≤30
100%数据:1≤N≤100
输入描述:
仅一行,一个正整数N。
输出描述:
一行,方案总数。
输出
13
很显然的题目,写出转移方程f[i][1]=i,f[i][j]=f[i][j-1]+f[i-1][j];
但long long 也只能写到n=30;
要用大数加法
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<new>
#include<ctime>
#include<vector>
#define MT(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const double E=2.718281828459;
const int INF=0x3f3f3f3f; string dp[][];
string add(string a,string b)
{
int lena = a.size(),lenb = b.size();
int cnt = ;
int len = max(lena,lenb);
string now = "";
for(int i=; i<len; i++)
{
if(i<lena && i<lenb)
{
cnt += a[i] -'' + b[i] - '';
now += cnt% + '';
cnt = cnt/;
}
else if(i<lena)
{
cnt += a[i] - '';
now += cnt% + '';
cnt = cnt/;
}
else if(i<lenb)
{
cnt += b[i] - '';
now += cnt% + '';
cnt = cnt/;
}
}
if(cnt)
now += cnt + '';
return now;
} int main()
{
int n;
scanf("%d",&n);
dp[][]="";
for(int i=;i<=n;i++)
dp[][i]="";
for(int i=;i<=n;i++)
{
for(int j=;j<=n-i+;j++)///这一行
{
dp[i][j]="";
for(int k=j;k<=n-i+;k++)
dp[i][j]=add(dp[i][j],dp[i-][k]);
}
}
string ans=add(dp[n][],dp[n][]);
string a=string(ans.rbegin(),ans.rend());
cout<<a<<endl;
}
大数当然用python啦
#py_1
a = []
for i in range(121):
a.append(0)
a[0]=1
a[1]=1
for i in range(121):
if i==0 or i==1:
continue
a[i] = 0
for j in range(i):
a[i] += a[j]*a[i-j]
n = int(input())
print(a[n+2]-1)
链接:https://ac.nowcoder.com/acm/contest/554/B
来源:牛客网
题目描述
输入描述:
输入数据为T组数据(1<=T<=10)。
每组数据有三行,每行三个数字,表示矩阵A中的元素值(0<=元素值<=255)。
输出描述:
对于每组数据,输出一个数字,表示矩阵A对应的伴随阵的行列式的值。
输出
1
1
直接用神奇的公式(谁让我还没有学过现代
#include<cstdio> int a[]; int main(){
int t;
scanf("%d",&t);
while(t--){
for(int i=;i<=;++i){
scanf("%d",&a[i]);
}
long long ans=a[]*a[]*a[]-a[]*a[]*a[]+
a[]*a[]*a[]-a[]*a[]*a[]+a[]*a[]*a[]-a[]*a[]*a[];
printf("%lld\n",ans*ans);
} return ;
}
链接:https://ac.nowcoder.com/acm/contest/554/C
来源:牛客网
题目描述
第一天可以产a吨粮食,第二天会变成前一天的a倍,以此类推。
n天后大臣准备把这些粮食尽可能多的平均分给b个城池
为了方便,每个城池分到的粮食都是整吨整吨哒!
剩下的粮食国王准备贪污
国王能贪到多少吨粮食呢?
输入描述:
输入的第一行为一个数字T(T<=100),表示数据输入的组数。
之后每行3个数字,分别表示 a, n, b(1<=a,n<= 1000,000,000;1<=b<=1000 )。
输出描述:
对于每组数据输出对应结果
直接用快速幂就可以了
题目的实际目的就是求a^n%b;
#include<iostream>
using namespace std;
int quick(int a,int b,int c){
int ans=;
while(b){
if(b&) ans=(ans*a)%c;
a=(a*a)%c;
b>>=;
}
return ans;
}
int main(){
int t;
int a,n,b;
cin>>t;
for(int i=;i<=t;i++){
cin>>a>>n>>b;
a=a%b;
cout<<quick(a,n,b)<<endl;
}
return ;
}
链接:https://ac.nowcoder.com/acm/contest/554/D
来源:牛客网
这是一个8*8的棋盘,wkroach有一个初始位置,每次移动不能超出棋盘并且必须遵循骑士行走的规则也
输入描述:
第一行输入一个正整数T代表测试样例数目
每组样例有三个正整数N R C(0<n<1000000000,0<R<9,0<C<9)代表此样例步数N及wkroach的初始点(R,C)。
输出描述:
对于每组测试数据,输出一个整数,表示总走法数。
太难聊,不会,先抄一下大佬的代码
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL; const LL MOD=1e9+;
const int MAX_S=;
const int f[][]={,, ,-, -,, -,-, ,, ,-, -,, -,-};
struct Matrix{
LL a[MAX_S][MAX_S];
Matrix (){
memset(a,,sizeof(a));
}
Matrix operator*(const Matrix &A){
Matrix B=Matrix();
for(int k=;k<MAX_S;++k)
for(int i=;i<MAX_S;++i)
for(int j=;j<MAX_S;++j)
B.a[i][j]=(B.a[i][j]+a[i][k]*A.a[k][j])%MOD;
return B;
}
};
int n,T;
Matrix e; void Fast_power(Matrix &res,int n);
int main()
{
e=Matrix();
int t=,x,y;
for(int i=;i<;++i)
for(int j=;j<;++t,++j)
for(int k=;k<;++k)
{
x=i+f[k][]; y=j+f[k][];
if(x>=&&x<&&y>=&&y<) e.a[t][x*+y]=;
}
cin>>T;
while(T--){
cin>>n>>x>>y;
Matrix res=Matrix();
t=(x-)*+y-;
for(int i=;i<MAX_S;++i)
res.a[t][i]=e.a[t][i];
Fast_power(res,n-);
LL ans=;
for(int i=;i<MAX_S;++i)
for(int j=;j<MAX_S;++j)
ans=(ans+res.a[i][j])%MOD;
cout<<ans<<endl;
} return ;
} void Fast_power(Matrix &res,int n)
{
Matrix A=e;
while(n){
if(n&) res=res*A;
A=A*A;
n>>=;
}
}
链接:https://ac.nowcoder.com/acm/contest/554/E
来源:牛客网
Like Mother's Day, there are also several celebrations have no fixed date, but are set in the form of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year", for example, as above, Mother's Day is on the second Sunday in May of a year, but also can be described as "the 2nd weekday 7 of the 5st month in a year"(A=5, B=2, C=7).
Now, to help remember these special days, HVT wants you to calculate all the exact date of such celebrations in the past and future hundreds of years, which means that you are given 4 numbers: A(1 ≤ A ≤ 12), B(B ≥ 1), C(1 ≤ C ≤ 7, 1=Monday,2=Tuesday,...,7=Sunday) and y(represents the year, 1850 ≤ y ≤ 2050), and you should write code to calculate the exact date of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y".
For your convenience, we will noice you that: January 1st, 1850 is a Tuesday.
输入描述:
The input contains multiple lines of test data, each line has 4 numbers: A B C and y.
输出描述:
For each input, you should output a exact date in the format of "yyyy/mm/dd"(When the number of digits is insufficient, 0 should be added to the front);
if the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y does not exist(for example, there will never be a 7th Monday in any months of any year), you should output "none" (without quotes).
输出
2018/04/08
2018/04/01
none
2018/02/28
思路:
根据基姆拉尔森计算公式直接求出要求的月的第一天然后模拟即可。
#include <bits/stdc++.h>
using namespace std;
int a,b,c,y;
int main()
{
while(scanf("%d%d%d%d",&a,&b,&c,&y)!=EOF)
{
int td,tm,ty;
td=,tm=a,ty=y;
if(tm==||tm==) {
tm+=;
ty-=;
}
int w=(td+*tm+*(tm+)/+ty+ty/-ty/+ty/)%;
int day[]={,,,,,,,,,,,,};
if((y%==&&y%)||(y%==)) day[]++;
int st=w;
int d=,num=;
while(st!=c-)
{
st=(st+)%;
d++;
}
while(num<b-&&d<=day[a])
{
num++;
d+=;
}
if(num==b-&&d<=day[a])
{
printf("%d/%02d/%02d\n",y,a,d);
}
else
{
printf("none\n");
}
}
return ;
}
链接:https://ac.nowcoder.com/acm/contest/554/H
来源:牛客网
题目描述
输入描述:
输入数据为T组数据(1<=T<=10)。
每组数据输入包含三个数字N,A,B(1<=N<=1000000,1<=A<B<=N)。
输出描述:
对于每组数据,输出一个整数,表示从第A个人到第B个人之间有多少人站着。
哈尔滨工程大学ACM预热赛 补题的更多相关文章
- 哈尔滨工程大学ACM预热赛 G题 A hard problem(数位dp)
链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) { if ( ...
- 哈尔滨工程大学ACM预热赛(A,C,H,I)
A: 链接:https://ac.nowcoder.com/acm/contest/554/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言655 ...
- 哈尔滨工程大学ACM预热赛
https://ac.nowcoder.com/acm/contest/554#question A #include <bits/stdc++.h> using namespace st ...
- 第十届山东省acm省赛补题(1)
今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...
- 第十届山东省acm省赛补题(2)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second ...
- 第13届 广东工业大学ACM程序设计大赛 C题 平分游戏
第13届 广东工业大学ACM程序设计大赛 C题 平分游戏 题目描述 转眼间又过了一年,又有一届的师兄师姐要毕业了. 有些师兄师姐就去了景驰科技实习. 在景驰,员工是他们最宝贵的财富.只有把每一个人 ...
- 2017河工大校赛补题CGH and 赛后小结
网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...
- Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100) rec ...
随机推荐
- 以太坊客户端geth的基本操作命令
以太坊客户端geth的基本操作命令搭建了私有链环境之后,整理了一下客户端的一些基本的操作命令: 启动命令重复上篇博客步骤,先将区块链客户端启动,命令如下: geth –datadir “%cd%\ch ...
- poyla计数问题
关于poyla定理,首先推荐两篇很好的文章阅读 2001-----符文杰<poyla原理及其应用> 2008-----陈瑜希<poyla计数法的应用> 在然后就是自己的学习笔记 ...
- JavaScript对象模型-执行模型
数据类型基本数据类型基本数据类型是JS语言最底层的实现.简单数值类型: 有Undefined, Null, Boolean, Number和String.注意,描述中的英文单词在这里仅指数据类型的名称 ...
- linux 忘记root(这里以centos 6.5为例)密码的解决办法
在使用linux的过程中有时候会忘记root用户的密码(尤其是进行交接而文档内容不全的时候),这个时候我们就可以进入单用户模式来重置root用户密码.下面来讲解重置root密码的方式,也可以说是破解r ...
- 使用VS进行打包程序解决生成两个文件的问题(压缩后只有一个exe)
使用VS打包创建setup相信大家都挺熟的了,不熟的话网上也有很多,就不做介绍了,现在给大家写下怎么将生成的那些文件夹以及setup.exe和.msi 文件打包成一个exe 我们这里使用的是Winra ...
- bzoj 2839: 集合计数【容斥原理+组合数学】
首先,考虑容斥,我们所要的答案是并集至少有\( k \)个数的方案数减去并集至少有\( k+1 \)个数的方案数加上并集至少有\( k \)个数的方案数-- 在n个数中选i个的方案数是\( C_{n} ...
- JavaScript中this的使用方法总结
JavaScript中this的使用方法总结 在JavaScript中,this的使用分为四种场景,具体请参考阮一峰老师关于this的讲解 第一种情况是纯函数使用 var x =1 ; functio ...
- Flutter开发移动端APP的入门教程及简单介绍
Dart&Flutter环境搭建 安装 dart SDK 如果只开发移动应用,那么您不需要Dart SDK; 只需安装Flutter. 这里就直接安装 Flutter (dart SDK已经集 ...
- 11.Flask-钩子函数
在Flask中钩子函数是使用特定的装饰器的函数.为什么叫做钩子函数呢,是因为钩子函数可以在正常执行的代码中,插入一段自己想要执行的代码,那么这种函数就叫做钩子函数. before_first_requ ...
- [Usaco2008 Feb]Eating Together麻烦的聚餐
Description 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的 ...