- T1 Luogu P1182
- T2 CJOJ1101
- T3 Luogu P1852
代码:
T1 :
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;
template<typename T = int>
inline T read()
{
T data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}
const int maxn(100010);
int n, k;
long long a[maxn], _max, s[maxn];
inline bool check(long long mid)
{
RG int l=1, tmpk=1;
for(RG int i=2;i<=n;i++)
{
if(s[i-1]-s[l-1]<=mid && s[i]-s[l-1]>mid)
{
l=i; tmpk++;
if(tmpk>k) return false;
}
}
return true;
}
int main()
{
file(seqa);
n=read(); k=read();
for(RG int i=1;i<=n;i++) s[i]=s[i-1]+(a[i]=read<long long>()), _max=max(_max, a[i]);
if(k==n) return printf("%lld\\n", _max)&0;
if(k==1) return printf("%lld\\n", s[n])&0;
long long l=_max, r=s[n];
while(l<r)
{
long long mid=(l+r)>>1;
bool ans=check(mid);
if(ans) r=mid;
else l=mid+1;
}
printf("%lld\\n", r);
return 0;
}
T2 :
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;
template<typename T = int>
inline T read()
{
T data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}
const int maxn(110);
int f[maxn][maxn][maxn], d1[maxn], d2[maxn], n, m;
int main()
{
file(time);
n=read(); m=read();
for(RG int i=1;i<=n;i++) d1[i]=read(), d2[i]=read();
clear(f, 63);
f[0][0][0]=0;
for(RG int i=1;i<=n;i++)
for(RG int j=0;j<=m;j++)
for(RG int k=0;k<=m;k++)
for(RG int l=0;l<=j;l++)
for(RG int p=0;p<=k;p++)
f[i][j][k]=min(f[i][j][k], max(f[i-1][l][p], (j-l)*d1[i]+(k-p)*d2[i]));
printf("%d\\n", f[n][m][m]);
return 0;
}
T3 : (std)
//http://blog.csdn.net/lych_cys/article/details/50805067
#include<iostream>
#include<cstring>
#include<cstdio>
#define inf 1000000000
using namespace std;
int len,k;
struct node
{
int x,y,z;
void init(){
scanf("%d%d%d",&x,&y,&z);
if (y<x) swap(x,y); if (z<x) swap(x,z); if (z<y) swap(y,z);
}
}a,b,p,q;
bool eql(node u,node v){
return u.x==v.x && u.y==v.y && u.z==v.z;
}
node getfa(node t,int rst)
{
for (len=0; rst; len+=k){
int u=t.y-t.x,v=t.z-t.y;
if (u==v) return t;
if (u<v){
k=min((v-1)/u,rst);
t.x+=k*u; t.y+=k*u; rst-=k;
} else{
k=min((u-1)/v,rst);
t.y-=k*v; t.z-=k*v; rst-=k;
}
}
return t;
}
int main()
{
a.init(); b.init();
p=getfa(a,inf); int len1=len;
q=getfa(b,inf); int len2=len;
if (!eql(p,q)){ puts("NO"); return 0; }
if (len1<len2){ swap(a,b); swap(len1,len2); }
a=getfa(a,len1-len2);
int l=0,r=len2,mid;
while (l<r){
mid=(l+r)>>1;
if (eql(getfa(a,mid),getfa(b,mid))) r=mid; else l=mid+1;
}
printf("YES\\n%d\\n",(l<<1)+len1-len2);
}
总结 :
这一次,骗分达到了极限,自认为比较满意了。(逃)