每日两小时编程之旅(五)
每日两小时编程之旅(五)
牛客篇-牛客算法周练9
A-符合条件的数
链接:https://ac.nowcoder.com/acm/contest/5902/A
来源:牛客网
众所周知,某个被共青团点名的学校的机房里有一个蒟蒻,名字叫做clccle,因为文化课成绩不好而经常被班主任gank,这次他遇到了一个很困(rui)难(zhi)的数学题,因为clccle非常辣鸡,所以他想到了聪明的你,你能帮Ta解决这个问题吗?
给定两个整数N,M,表示区间 [2N,2M),请求出在这个区间里有多少个整数i满足i % 7=1
输入描述:
一行,两个整数N,M 0<=N<M<=65
输出描述:
一个数字ans,表示满足条件的数字的个数
示例1
输入
2 3
输出
0
说明
在区间[22,23 )里满足条件的整数的个数为零 ,(4,5,6,7,8因为在开区间边界上所以不做考虑)
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll n,m;
int main()
{
cin>>n>>m;
n=1LL<<n,m=1LL<<m;//在c++中,LL是long long int的意思
//1LL一般与*共用,即1LL*或*1LL在这种情况下,被赋值的变量将会变成长长整型,可以用来防止数字过大存不下qaq。
n--;
m--;
cout<<(m-1)/7-(n-1)/7<<endl;//[m,n)区间内有多少个整数i满足i%x=y,公式如下:
m--,n--,(m-y)/x-(n-y)/x
return 0;
} B-Relic Discobery
链接:https://ac.nowcoder.com/acm/contest/5902/B
来源:牛客网
Recently, paleoanthropologists have found historical remains on an island in the Atlantic Ocean. The most inspiring thing is that they excavated in a magnificent cave and found that it was a huge tomb. Inside the construction, researchers identified a large number of skeletons, and funeral objects including stone axe, livestock bones and murals. Now, all items have been sorted, and they can be divided into N types. After they were checked attentively, you are told that there are Ai items of the i-th type. Further more, each item of the i-th type requires Bi million dollars for transportation, analysis, and preservation averagely. As your job, you need to calculate the total expenditure.
输入描述:
The first line of input contains an integer T which is the number of test cases. For each test case, the first line contains an integer N which is the number of types. In the next N lines, the i-th line contains two numbers Ai and Bi as described above. All numbers are positive integers and less than 101.
输出描述:
For each case, output one integer, the total expenditure in million dollars.
示例1
输入
1 2 1 2 3 4
输出
14
#include<bits/stdc++.h>
using namespace std;
int t,n;
int a,b;
int main()
{
cin>>t;
while(t--)
{
int ans=0;
cin>>n;
while(n--)//相乘之和即可
{
cin>>a>>b;
ans+=a*b;
}
cout<<ans<<endl;
}
return 0;
} 洛谷篇(算法1-1)模拟与高精度
P4924[1007]魔法少女小Scarlet
#include<bits/stdc++.h>
using namespace std;//简单模拟即可
int g[510][510],tot,f[510][510];//f数组充当临时数组
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
g[i][j]=++tot;
for(int i=1;i<=m;i++) {
int a,b,r,opt;
scanf("%d %d %d %d",&a,&b,&r,&opt);//下面的分析都是针对那一块矩阵而言的
if(opt==0) {//第i行第j个 变成倒数第i列第j个 顺时针
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
f[a-b+j][a+b-i] = g[i][j];
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
g[i][j] = f[i][j];
}
else { //第i行第j个 变成第i列倒数第j个 逆时针
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
f[a+b-j][b-a+i] = g[i][j];
for(int i=a-r;i<=a+r;i++)
for(int j=b-r;j<=b+r;j++)
g[i][j] = f[i][j];
}
}
for(int i=1;i<=n;i++) {//输出结果咯
for(int j=1;j<=n;j++)
printf("%d ",g[i][j]);
printf("\n");
}
return 0;
} P1328生活大爆炸石头剪刀布
#include<bits/stdc++.h>
using namespace std;
int n,na,nb;
int a[220],b[220];
int numa,numb;
int main()
{
cin>>n>>na>>nb;//理清思路,简单模拟即可
for(int i=0;i<na;i++) cin>>a[i];
for(int i=0;i<nb;i++) cin>>b[i];
for(int i=0;i<n;i++)
{
if(a[i%na]==0&&(b[i%nb]==2||b[i%nb]==3)) numa++;
else if(a[i%na]==1&&(b[i%nb]==0||b[i%nb]==3)) numa++;
else if(a[i%na]==2&&(b[i%nb]==1||b[i%nb]==4)) numa++;
else if(a[i%na]==3&&(b[i%nb]==2||b[i%nb]==4)) numa++;
else if(a[i%na]==4&&(b[i%nb]==0||b[i%nb]==1)) numa++;
else if(a[i%na]==b[i%nb]) numa=numa,numb=numb;
else numb++;
}
cout<<numa<<" "<<numb;
return 0;
}
查看20道真题和解析