您的位置:首页 > 其它

10.18考试总结

2017-10-19 16:57 169 查看
1.打牌

    题目大意:给一组数,可以把相同的两个数组成对子,或三个连续的数组成顺子,问最多组成情况;

       感想:半个小时,写了个dp感觉没什么问题,就走了,结果wa了7个点。。后来发现一维转移不了,只能用vector开二维,,过了。dp[i][j]表示前i个,j表示第i个牌的个数,然后转移。或者直接贪心。(下面代码是贪心的# include <cstdio>
# include <iostream>
# include <cctype>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
using namespace std;
typedef long long ll;
int Read(){
int f=1,i=0;char ch;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-'){f=-1;ch=getchar();}
for(;ch>='0'&&ch<='9';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
int n,a[1000010];
int main()
{
n=Read();
int x;
for(int i=1;i<=n;++i)
{
x=Read();
a[x]++;
}
int ans=0;
for(int i=1;i<=n;++i)
{
ans+=a[i]/2;
a[i]%=2;
if(i+1<n)
{
if(a[i]&&a[i+1]%2&&a[i+2])
{
ans++;
a[i]--;
a[i+1]--;
a[i+2]--;
}
}
}
cout<<ans<<endl;
return 0;
}

2.弹球
       题目大意:将一个球从左上角45°射入一个n*m的矩形,每经过一个格子会染上色,小球碰壁后以45°接着弹,直到弹到某个角落。问只被染色一次的方格的个数。

       感想:做了3个小时没想出来,最后放弃了,以致花了20分钟打t3,所以两道题都挂了。直接说正解:先把每个点连线,则原矩形变成了(n-1)*(m-1)的矩形。然后观察得出一共有(n-1)*(m-1)/gcd(n-1),(m-1)+1·个点,现在想办法去除重复的点,再次观察得出重复的点有(n-2)*(m-2)/gcd(n-1,)平方,直接3行代码搞定。这题纯属浪费我青春。

# include <cstdio>
# include <iostream>
# include <cctype>
# include <cstring>
# include <string>
# include <cmath>
# include <list>
# include <queue>
# include <algorithm>
using namespace std;
typedef long long ll;
int Read(){
int f=1,i=0;char ch;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-'){f=-1;ch=getchar();}
for(;ch>='0'&&ch<='9';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
ll t,n,m;
ll gcd(ll a,ll b)
{
if(b==0) return a;
return gcd(b,a%b);
}
int main()
{
t=Read();
while(t--)
{
n=Read()-1,m=Read()-1;
ll k=gcd(n,m);
n/=k,m/=k;
cout<<n*m*k+1-(n-1)*(m-1)<<endl;
}
}
3.装盒子
    题目大意:给许多x*y的盒子小盒子可以套在大盒子里,(a任何边长都不大于b的,则a比b小),求最后盒子的面积

       感想:没什么感想,题都没怎么看。。。正解:最小费用流,每个盒子拆点,中间连接流量为1的边,表示每个盒子只能用一次。s向盒子连流量为1费用为盒子大小的边,再把盒子连向t,做一遍最小费用流。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define ll long long
using namespace std;

int getint()
{
int i=0,f=1;char c;
for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
if(c=='-')f=-1,c=getchar();
for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
return i*f;
}

const int N=405,INF=0x3f3f3f3f;
const int M=N*N*2;
struct node
{
int x,y;
friend inline bool operator == (const node &a,const node &b)
{return a.x==b.x&&a.y==b.y;}
friend inline bool operator < (const node &a,const node &b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
}a
;
int n,S,T,sum,ans;
int tot=1,first
,next[M],to[M],cap[M],cost[M];
int dis
;
bool exist
,visit
;
queue<int>q;

void add(int x,int y,int f,int c)
{
next[++tot]=first[x],first[x]=tot,to[tot]=y,cap[tot]=f,cost[tot]=c;
next[++tot]=first[y],first[y]=tot,to[tot]=x,cap[tot]=0,cost[tot]=-c;
}

bool SPFA()
{
for(int i=S;i<=T;i++)visit[i]=false,dis[i]=-INF;
dis[S]=0,exist[S]=true;
q.push(S);
while(!q.empty())
{
int u=q.front();
q.pop();exist[u]=false;
for(int e=first[u];e;e=next[e])
{
int v=to[e];
if(dis[v]<dis[u]+cost[e]&&cap[e])
{
dis[v]=dis[u]+cost[e];

9418
if(!exist[v])q.push(v),exist[v]=true;
}
}
}
return dis[T]!=-INF;
}

int dinic(int u,int flow)
{
if(u==T)
{
ans+=dis[T]*flow;
return flow;
}
int res=0;
visit[u]=1;
for(int e=first[u];e;e=next[e])
{
int v=to[e];
if(dis[v]==dis[u]+cost[e]&&cap[e]&&!visit[v])
{
int delta=dinic(v,min(flow-res,cap[e]));
if(delta)
{
cap[e]-=delta,cap[e^1]+=delta;
res+=delta;if(res==flow)break;
}
}
}
return res;
}

void maxflow()
{
while(SPFA())dinic(S,INF);
}

int main()
{

n=getint();
for(int i=1;i<=n;i++)
a[i].x=getint(),a[i].y=getint();
sort(a+1,a+n+1);
n=unique(a+1,a+n+1)-a-1;
S=0,T=2*n+1;
for(int i=1;i<=n;i++)
sum+=a[i].x*a[i].y,add(S,i,1,0),add(i+n,T,1,0);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j&&a[i].x>=a[j].x&&a[i].y>=a[j].y)
add(i,j+n,1,a[j].x*a[j].y);
maxflow();
cout<<sum-ans;
return 0;
}

总结:做题要分顺序,先把能拿的分拿到,别死磕,虽然noip难度分布均匀,但难免会出现去年day1t2的悲剧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: