Answer: 1478
I'm not quite sure about the answer to this question. I recorded 0 when I was considering a straight, so my answer was 14, but if I didn't consider 0, the answer would be 4, and the answer would most likely be 4
Analysis: We first take weeks as a unit and do 5*a+2*b questions in one week, then we do n/(5*a+2*b) weeks completely, and these weeks do n/(5*a +2*b)*(5*a+2*b) questions, the division in the computer is rounded down, and the remaining questions can be calculated directly day by day . The following is the code:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
using namespace std;
int main()
{
long long a,b,n,ans=0;
cin>>a>>b>>n;
ans=n/(5*a+2*b)*7;
if(ans/7*(5*a+2*b)==n)
printf("%lld",ans);
else
{
int cnt=1;
n-=ans/7*(5*a+2*b);
while(n>0)
{
if(cnt<=5) n-=a;
else n-=b;
ans++;cnt++;
}
printf("%lld",ans);
}
return 0;
}
Look here: The 13th Blue Bridge Cup Provincial D: Building Shrubs (Thinking) - AC__dream's Blog - CSDN Blog
Look here: The 13th Blue Bridge Cup Provincial E: X-ary subtraction (greedy) - AC__dream's blog - CSDN blog
sample input
3 4 10
1 2 3 4
5 6 7 8
9 10 11 12
Sample output
19
I didn't expect the correct solution during the exam. I wrote a 4-fold for loop directly with the prefix sum, and I can pass some examples. The following is the code:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
using namespace std;
const int N=503;
long long a[N][N],s[N][N];
int main()
{
int n,m;
long long K;
scanf("%d%d%lld",&n,&m,&K);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
scanf("%lld",&a[i][j]);
s[i][j]+=s[i-1][j]+s[i][j-1]+a[i][j]-s[i-1][j-1];
}
long long ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for(int k=1;k<=i;k++)
for(int l=1;l<=j;l++)
if(s[i][j]-s[i][l-1]-s[k-1][j]+s[k-1][l-1]<=K) ans++;
printf("%lld",ans);
return 0;
}
The output is an integer representing the answer.
样例输入
2 1
2 2 4
4 4 2
0 0 5
Sample output
2
There will be time to sort out later...
output answer modulo 1e9+7
sample input
5 10
Sample output
14
Output an integer representing the answer.
sample input
6
2 1 4 2 6 7
Sample output
5
There will be time to sort out later...