完败…… 掉了101Rank……
前一天是网赛,下午有网赛,当晚比赛的时候实在是僵尸一般的困死了……
哭……C还fst了……只剩一个A让我怎么活……
自然还是献上3题的解题报告——
这题呢是说有个人想要去n个地方旅游,有单次票一次去一个地方要花a元,也有联票一次去m个地方,花b元,问去n个地方都旅游完最少花多少钱。
之前我想的是可能要刚好去n个地方吧,然后给想复杂了,这题的题意是说旅游到了n个就行了,就是多了也成,那么——
对于m个地方,是单程还是联票划算,讨论一下,然后m的整数倍都这么来,最后剩下的几个地方再讨论下就可以了
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
int main()
{
int n,m,a,b;
cin>>n>>m>>a>>b;
cout<<min(a*n,min((n/m+1)*b,((n+m)%m)*a+(n/m)*b))<<endl;
return 0;
}
这道题实际上是找i*j>=6n,i>a,j>b的i*j最小整数解。遍历肯定是NodoNodie。
先挑出两个长度之间较小的边记作a,另一个叫他b,先考虑a,很明显我们可以遍历a的范围是a~n/a(除不尽的话+1),对于每个a我们来考虑对应这个a,b应该的值(当然如果刚好就是6n直接输出finish),每次刷新当前离6n最近的面积s记录下来。
啊过不去的可以试试这个: 我当时就会有一组数据过不去 4 7 30,是怎么回事呢,细节问题~ 比如那个+1,
代码如下
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
ll n, a, b, s, x, y, t;
int main()
{
cin>>n>>a>>b;
n*=6; s = -1;
if(a*b>=n)
{
s = a*b;
x = a; y = b;
}
else
{
if(a<b)
{
for(ll i=a; i*i<=n; i++)
{
t = max(n%i==0?n/i:n/i+1,b);
if(i*t<s||s<0) {x=i; y=t; s=x*y;}
}
}
else
{
for(ll i=b; i*i<=n; i++)
{
t = max(n%i==0?n/i:n/i+1,a);
if(t*i<s||s<0) {y=i; x=t; s=x*y;}
}
}
}
cout<<s<<endl<<x<<' '<<y<<endl;
return 0;
}
这题是问,有一串数字,我们把它分为三段,三段的和相等,有多少种分法。
首先连3个数字都没有的串串自然是边儿呆着去了
然后我们先算出个全和,然后1/3的点和2/3的点的值就知道了不是么~
然后找出所有这些点,最后……1/3的点在2/3的点左边就行咯(千万注意有的时候和为0的时候别让其中某一段没有分配到数字)~
然后为了加速用了下dp~
代码如下
Code:
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
#define maxn 500010
typedef long long ll;
ll a[maxn], n, ls[maxn], rs[maxn], l[maxn], r[maxn], s;
int main()
{
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i], s+=a[i];
if(s%3)
{
cout<<0<<endl;
return 0;
}
s/=3;
for(int i=1; i<=n; i++)
{
ls[i] = ls[i-1] + a[i];
if(ls[i]==s) l[i] = l[i-1] + 1;
else l[i] = l[i-1];
}
ll ans = 0;
for(int i=n; i>0; i--)
{
rs[i] = rs[i+1] + a[i];
if(rs[i]==s&&i>2) ans += l[i-2];
}
cout<<ans<<endl;
return 0;
}