头大
这个暑假完就要去搞NOIP了。。。
暑假55天也就20次测试。。。为防万一我还是每次测试玩都写个总结。。
Day2 (120/300)
T1 能源 (100/100)
题目
简单二分即可a_a
MY.CPP/STD.CPP
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int n,ai,sum,maxx,power[1005],bater[1005];
double k,ans;
void find()
{
double l=1,r=maxx;
while(r-l >= 0.00000001)
{
int jud = (l+r)/2;;
double mid = (l+r)/2;
double index = k/100;
double trie = ((power[1000]-power[jud])-mid*(bater[1000]-bater[jud]))*(1-index);
double limt = (bater[jud]*mid-power[jud]);
if(trie<=limt) r = mid;
if(trie>limt) l = mid;
}
printf("%0.6lf",l);
}
int main()
{
cin >> n >> k;
for(int i=1;i<=n;i++)
{
cin >> ai;
power[ai] += ai;
bater[ai] += 1;
maxx = max(maxx,ai);
sum += ai;
}
for(int i=1;i<=1000;i++)
{
power[i] += power[i-1];
bater[i] += bater[i-1];
}
find();
}
T2 电影 (0/100)
题目
一开始我以为要用数位dp就没做,后来想水几分结果答案没有-1和w的点。。。
行吧我认输
STD.CPP
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int n,m,k,d,e,h;
long long a,l,ans,i,j;
double b[200005],c[200005];
map<double,int> f;
map<double,int> g;
int gcd(long long a,long long b)
{
if(!a) return b;
return gcd(b%a,a);
}
inline long long fan(long long x)
{
long long k=x,a=0;
for(;k;k/=10)
a = a*10+k%10;
return a;
}
int main()
{
cin >> n >> m >> k;
if(n>m) swap(n,m);
ans = (n+1)*(m+1);
for(i=1;i<=max(n,m);i++)
{
a = fan(i);
l = gcd(a,i);
b[i] = (double)(a/l)/(i/l);
c[i] = (double)(i/l)/(a/l);
}
for(i=1;i<=n;i++)f[b[i]]++;
for(j=0;j<m&&h<k;)
{
j++; g[b[j]]++;
h += f[c[j]];
}
if(h<k)
{cout << -1 << endl;return 0;}
i = n; ans = i*j;
for(;i;i--)
{
f[b[i]]--; h -= g[c[i]];
for(;j<m&&h<k;)
{
j++; h += f[c[j]];
g[b[j]]++;
}
if(h<k) break;
ans = min(ans,(i-1)*j);
}
cout << ans;
}
话说map好玩,vector也是
T3 流(网络流) (20/100)
题目
MY.CPP
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int n,inmini,inmaxx,otmini,otmaxx;
bool exist[20];
int check[10],value;
struct node1{
int u;
int v;
int minn;
int maxx;
int val;
}side[20];
struct node2{
int in;
int ot;
int inmin; int inmax;
int otmin; int otmax;
}dot[10];
void dfs(int cn,int n)
{
exist[cn] = true;
for(int i=1;i<=(n*(n-1)/2);i++)
{
int h = side[i].v;
if(side[i].u==cn&&!exist[side[i].v])
{
int hihi1,hihi2;
hihi1 = max(dot[h].inmin,dot[h].otmin);
hihi2 = min(dot[h].inmax,dot[h].otmax);
check[h] += hihi1;
value += hihi2*hihi2 + side[i].val;
dfs(h,n);
}
}
}
int main()
{
freopen("flow.in","r",stdin);
freopen("flow.out","w",stdout);
int n;
cin >> n;
for(int i=1;i<=(n*(n-1)/2);i++)
{
cin >> side[i].u >> side[i].v >> side[i].minn >> side[i].maxx >> side[i].val;
dot[side[i].u].ot +=1; dot[side[i].v].in +=1;
dot[side[i].u].otmin += side[i].minn;
dot[side[i].u].otmax += side[i].maxx;
dot[side[i].v].inmin += side[i].minn;
dot[side[i].v].inmax += side[i].maxx;
}
if(n==2)
{
cout << side[1].minn << " " << side[1].minn*side[1].minn+side[1].val;
return 0;
}
for(int i=2;i<=n-1;i++)
{
if(dot[i].inmax<dot[i].otmin||dot[i].inmin>dot[i].otmax)
{
cout << "-1 -1" << endl;
return 0;
}
}
dfs(1,n);
cout << check[n] << " " << value;
}
过了两个点但完全没有参考价值思路是完全错的。。
神奇的是样例数据全过
网络流我还是渣。。。
STD.CPP(玄学的网络流)
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b,c,d,e,f[10][10],in[10],out[10],g,h,i,j,k,l,m,n,Min[10][10],Max[10][10],sum[10][10],ansmax,ansflow;
inline void dfs(int x,int y,int flow,int ans){
if(flow>ansflow)return;
if(x==n){
l=1;
if(flow<ansflow){ansflow=flow;ansmax=ans;}
else if(flow==ansflow){ansmax=max(ans,ansmax);}
return;
}
if(y>n){dfs(x+1,x+2,flow,ans);return;}
if(x>1&&y==n){
int s=in[x];
s-=out[x];
if(s>Max[x][y]||s<Min[x][y])return;
dfs(x,y+1,flow,ans+s*s+(s>0)*(sum[x][y]));
return ;
}
for(int i=Min[x][y];i<=Max[x][y];i++){
out[x]+=i;in[y]+=i;
if(x==1)dfs(x,y+1,flow+i,ans+i*i+(i>0)*sum[x][y]);
else dfs(x,y+1,flow,ans+i*i+(i>0)*sum[x][y]);
out[x]-=i;in[y]-=i;
}
}
int main(){
freopen("flow.in","r",stdin);
freopen("flow.out","w",stdout);
scanf("%d",&n);
if(n==1){
printf("%d %d",0,0);
}
else if(n==2){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
if(c)printf("%d %d",c,e+c*c);
else printf("%d %d",c,0);
}
else if(n==3){
for(i=1;i<=3;i++){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
f[a][b]=1;
Min[a][b]=c;
Max[a][b]=d;
sum[a][b]=e;
}
if(Max[1][2]<Min[2][3]||Min[1][2]>Max[2][3]){printf("-1 -1");return 0;}
h=max(Min[1][2],Min[2][3]);if(h)g=sum[1][2]+h*h+sum[2][3]+h*h;
h+=Min[1][3];if(Min[1][3])g+=sum[1][3]+Min[1][3]*Min[1][3];
printf("%d %d",h,g);
}
else{
//printf("-1 -1");return 0;
m=n*(n-1)/2;ansflow=10000000;
for(i=1;i<=m;i++){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
f[a][b]=1;
Min[a][b]=c;
Max[a][b]=d;
sum[a][b]=e;
}
dfs(1,2,0,0);
if(l)printf("%d %d",ansflow,ansmax);
else printf("-1 -1");
}
return 0;
}
}