前言
今天考试还是只有Rank5我很畏惧,感觉要被刷了...(绝望,对不起KingBenQi).其实这一套题目我硬盘里都有,只是今天忘记翻了..绝望.
T1
小奇挖矿
这道题目直接贪心就好了(可能是DP吧..)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define re register
using namespace std;
inline int gi(){
int f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
double k,c,w,cost[100010];int n,type[100010];
double max(double a,double b){
return a>b?a:b;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("explo.in","r",stdin);
freopen("explo.out","w",stdout);
#endif
scanf("%d%lf%lf%lf",&n,&k,&c,&w);
double ans=0;
for(re int i=1;i<=n;i++){
type[i]=gi();scanf("%lf",&cost[i]);
}
for(re int i=n;i>=1;i--){
if(type[i]==1)ans=max(ans,ans*(1-0.01*k)+cost[i]*w);
else ans=max(ans,ans*(1+0.01*c)-cost[i]*w);
}
printf("%.2lf\n",ans);
return 0;
}
T2
小奇的数列
由于nzr运用一些玄学的暴力优化使得这道题目不需要平衡树就可以通过.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#define ll long long
#define re register
using namespace std;
inline ll gi(){
ll f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
ll n,q,a[500010],sum[500010];
bool bj[510];
int main(){
#ifndef ONLINE_JUDGE
freopen("seq.in","r",stdin);
freopen("seq.out","w",stdout);
#endif
n=gi(),q=gi();
for(re ll i=1;i<=n;i++){
a[i]=gi();
sum[i]=sum[i-1]+a[i];
}
while(q--){
ll l=gi(),r=gi(),p=gi();ll ans=1e18;
if(r-l+1>p){puts("0");continue;}
memset(bj,0,sizeof(bj));
ll size=sqrt(p)/2;
for(re int qujian=l-1;qujian<=r;qujian++){
for(re ll k=size;k>=0;k--)
if(bj[(p+sum[qujian]-k)%p]){
ans=min(ans,k);if(!ans)break;
}
if(!ans)break;
bj[sum[qujian]%p]=1;
}
if(ans!=1e18){
printf("%lld\n",ans);
continue;
}
int flag=0;
for(re ll i=l;i<=r;i++){
for(re ll j=i;j<=r;j++){
ans=min(ans,(sum[j]-sum[i-1])%p);
if(sum[i-1]==sum[j]){
flag=1;break;
}
}
if(flag)break;
}
printf("%lld\n",ans);
}
return 0;
}
T3
小奇回地球
直接SPFA判负环然后二分答案就出来了...
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#define ll long long
#define re register
using namespace std;
inline int gi(){
int f=1,sum=0;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
const int Inf=1000000000+10;
struct node{
int to,nxt,w;
}e[1000010];
int front[110],cnt,mark[110],can[110],dis[110],n;
void Add(int u,int v,int w){
e[++cnt]=(node){v,front[u],w};front[u]=cnt;
}
void dfscan(int u){
mark[u]=1;
for(re int i=front[u];i;i=e[i].nxt)
if(!mark[e[i].to])dfscan(e[i].to);
}
bool dfs(int u,int mid){
mark[u]=1;
for(re int i=front[u];i;i=e[i].nxt){
int v=e[i].to;
if(can[v] && dis[v]>dis[u]+e[i].w+mid){
if(mark[v])return 1;
dis[v]=dis[u]+e[i].w+mid;
if(dfs(v,mid))return 1;
}
}
mark[u]=0;
return 0;
}
int vis[100010];
void spfa(int mid){
queue<int >Q;
while(!Q.empty())Q.pop();
Q.push(1);dis[1]=0;vis[1]=0;
while(!Q.empty()){
int u=Q.front();Q.pop();
for(re int i=front[u];i;i=e[i].nxt){
int v=e[i].to;
if(dis[v]>dis[u]+e[i].w+mid && can[v]){
dis[v]=dis[u]+e[i].w+mid;
if(!vis[v]){
vis[v]=1;Q.push(v);
}
}
}
vis[u]=0;
}
}
bool check(int mid){
for(re int i=1;i<=n;i++)
if(can[i]){
for(re int j=1;j<=n;j++)dis[j]=Inf;
memset(mark,0,sizeof(mark));
if(dfs(i,mid))return 0;
}
for(re int i=1;i<=n;i++){
dis[i]=Inf;vis[i]=0;
}
spfa(mid);
if(dis[n]<0 || dis[n]==Inf)return 0;
return 1;
}
int m;
int main(){
freopen("earth.in","r",stdin);
freopen("earth.out","w",stdout);
int T=gi();
while(T--){
memset(front,0,sizeof(front));cnt=0;
n=gi();m=gi();
for(re int i=1;i<=m;i++){
int u=gi(),v=gi(),w=gi();
Add(u,v,w);
}
memset(mark,0,sizeof(mark));
dfscan(1);memset(can,1,sizeof(can));
for(re int i=1;i<=n;i++)if(!mark[i])can[i]=0;
for(re int i=1;i<=n;i++)
if(can[i]){
memset(mark,0,sizeof(mark));
dfscan(i);
if(!mark[n])can[i]=0;
}
int l=-100000,r=100000,ans=-1;
while(l<=r){
int mid=(l+r)/2;
if(check(mid)){
ans=dis[n];r=mid-1;
}
else l=mid+1;
}
printf("%d\n",ans);
}
return 0;
}
原文地址:https://www.cnblogs.com/cjgjh/p/9530554.html
时间: 2024-11-14 19:56:24