A .Abstract Art

题意:求多个多边形的面积并。

思路:模板题。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double inf=1e200;
const double eps=1e-;
const double pi=*atan(1.0);
int dcmp(double x){ return fabs(x)<eps?:(x<?-:);}
struct point{
double x,y;
point(double a=,double b=):x(a),y(b){}
};
point operator +(point A,point B) { return point(A.x+B.x,A.y+B.y);}
point operator -(point A,point B) { return point(A.x-B.x,A.y-B.y);}
point operator *(point A,double p){ return point(A.x*p,A.y*p);}
point operator /(point A,double p){ return point(A.x/p,A.y/p);}
bool operator ==(const point& a,const point& b){
return fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps;
}
double dot(point A,point B){ return A.x*B.x+A.y*B.y;}
double det(point A,point B){ return A.x*B.y-A.y*B.x;}
double det(point O,point A,point B){ return det(A-O,B-O);}
double length(point A){ return sqrt(dot(A,A));}
double area(vector<point>p){
double ans=; int sz=p.size();
for(int i=;i<sz-;i++) ans+=det(p[i]-p[],p[i+]-p[]);
return ans/2.0;
}
double seg(point O,point A,point B){
if(dcmp(B.x-A.x)==) return (O.y-A.y)/(B.y-A.y);
return (O.x-A.x)/(B.x-A.x);
}
vector<point>pp[];
pair<double,int>s[*];
double polyunion(vector<point>*p,int N){
double res=;
for(int i=;i<N;i++){
int sz=p[i].size();
for(int j=;j<sz;j++){
int m=;
s[m++]=make_pair(,);
s[m++]=make_pair(,);
point a=p[i][j],b=p[i][(j+)%sz];
for(int k=;k<N;k++){
if(i!=k){
int sz2=p[k].size();
for(int ii=;ii<sz2;ii++){
point c=p[k][ii],d=p[k][(ii+)%sz2];
int c1=dcmp(det(b-a,c-a));
int c2=dcmp(det(b-a,d-a));
if(c1==&&c2==){
if(dcmp(dot(b-a,d-c))){
s[m++]=make_pair(seg(c,a,b),);
s[m++]=make_pair(seg(c,a,b),-);
}
}
else{
double s1=det(d-c,a-c);
double s2=det(d-c,b-c);
if(c1>=&&c2<) s[m++]=make_pair(s1/(s1-s2),);
else if(c1<&&c2>=) s[m++]=make_pair(s1/(s1-s2),-);
}
}
}
}
sort(s,s+m);
double pre=min(max(s[].first,0.0),1.0),now,sum=;
int cov=s[].second;
for(int j=;j<m;j++){
now=min(max(s[j].first,0.0),1.0);
if(!cov) sum+=now-pre;
cov+=s[j].second;
pre=now;
}
res+=det(a,b)*sum;
}
}
return res/;
}
int main()
{
int N,M,i,j; point tp;
scanf("%d",&N);
for(i=;i<N;i++){
scanf("%d",&M);
for(j=;j<M;j++){
scanf("%lf%lf",&tp.x,&tp.y);
pp[i].push_back(tp);
}
}
double t1=,t2=polyunion(pp,N);
for(i=;i<N;i++) t1+=area(pp[i]);
printf("%f %f\n",-t1,-t2);
return ;
}

B .Craters

题意:给定N个圆,让你用最小的周长把这些圆包起来,且满足到圆的最近距离不小于10.

思路:把每个圆的半径增加10,然后等分1000份,然后求凸包即可。

#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
const double inf=1e200;
const double eps=1e-;
const double pi=*atan(1.0);
int dcmp(double x){ return fabs(x)<eps?:(x<?-:);}
struct point{
double x,y;
point(double a=,double b=):x(a),y(b){}
};
point operator +(point A,point B) { return point(A.x+B.x,A.y+B.y);}
point operator -(point A,point B) { return point(A.x-B.x,A.y-B.y);}
point operator *(point A,double p){ return point(A.x*p,A.y*p);}
point operator /(point A,double p){ return point(A.x/p,A.y/p);}
point rotate(point A,double rad){
return point(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
bool operator ==(const point& a,const point& b) {
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
double dot(point A,point B){ return A.x*B.x+A.y*B.y;}
double det(point A,point B){ return A.x*B.y-A.y*B.x;}
double det(point O,point A,point B){ return det(A-O,B-O);}
double length(point A){ return sqrt(dot(A,A));}
double angle(point A,point B){ return acos(dot(A,B)/length(A)/length(B));}
double area(vector<point>p){
double ans=; int sz=p.size();
for(int i=;i<sz-;i++) ans+=det(p[i]-p[],p[i+]-p[]);
return ans/2.0;
}
double seg(point O,point A,point B){
if(dcmp(B.x-A.x)==) return (O.y-A.y)/(B.y-A.y);
return (O.x-A.x)/(B.x-A.x);
}
bool cmp(point a,point b){ return a.x==b.x?a.y<b.y:a.x<b.x; }
void convexhull(point *a,int n,point *ch,int &top)
{
sort(a+,a+n+,cmp);
top=;
for(int i=;i<=n;i++){
while(top>=&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
int ttop=top;
for(int i=n-;i>=;i--){
while(top>ttop&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
}
point ch[],p[];
int main()
{
int N,i,j,tot=,top; double ans,one=pi/,x,y,r;
scanf("%d",&N);
for(i=;i<=N;i++){
scanf("%lf%lf%lf",&x,&y,&r); r+=;
for(j=;j<=;j++){
tot++; p[tot].x=x+r*cos(one*j); p[tot].y=y+r*sin(one*j);
}
}
convexhull(p,tot,ch,top);
for(i=;i<top;i++) ans+=length(ch[i]-ch[i+]);
printf("%.10lf\n",ans);
return ;
}

C .DRM Messages

题意:字符串操作模拟。

思路:模拟。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn];
void solve(int L,int R)
{
int sum=;
rep(i,L,R) sum+=c[i]-'A';
sum%=;
rep(i,L,R) c[i]=(c[i]-'A'+sum+)%+'A';
}
int main()
{
int N; scanf("%s",c+);
N=strlen(c+);
solve(,N/);
solve(N/+,N);
rep(i,,N/){
c[i]=(c[i]-'A'+(c[i+N/]-'A')+)%+'A';
}
rep(i,,N/) putchar(c[i]);
return ;
}

D .Game of Throwns

题意:模拟题。

思路:模拟。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int q[maxn],tot;
int read()
{
int x=,F=; char c=getchar();
while(c!='-'&&c!='u'&&!(c>=''&&c<='')) c=getchar();
if(c=='-') F=-,c=getchar();
else if(c=='u') {
rep(i,,) c=getchar(); return maxn;
}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return F*x;
}
int main()
{
int N,K,x,P=; scanf("%d%d",&N,&K);
rep(i,,K) {
x=read();
if(x==maxn) {
x=read();
tot-=x;
}
else q[++tot]=x;
}
rep(i,,tot) P=((P+q[i])%N+N)%N;
printf("%d\n",P);
return ;
}

E .Is-A? Has-A? Who Knowz-A?

题意:题意可能没有解释清楚。N个名字,M个传递关系,Q次询问,反正就是有两种传递关系,is和has,A(has or is)->B; B->C; C->D;像这样的传递关系,假如全部都是is,则A可以推出isD;否则可以推出A has D。N<=500。

思路:因为N<500,直接DFS即可,复杂度O(N^3);注意自己和自己有is关系,但是没有has关系。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int dis[maxn][maxn][],tot;
struct in{
int x,y,opt;
in(){}
in(int xx,int yy,int oo):x(xx),y(yy),opt(oo){}
};
queue<in>q; map<string,int>mp;
map<int,string>F;
void name(string s){
if(mp.find(s)==mp.end()) {
mp[s]=++tot; F[tot]=s;
}
}
void DFS()
{
while(!q.empty()){
int x=q.front().x,y=q.front().y,op=q.front().opt; q.pop();
//cout<<":"<<F[x]<<" "<<F[y]<<" "<<op<<endl;
dis[x][y][op]=;
for(int i=;i<=tot;i++){
if(!dis[x][i][]&&dis[y][i][]){
dis[x][i][]=; q.push(in(x,i,));
}
if(!dis[x][i][]&&dis[y][i][]&&op==){
dis[x][i][]=; q.push(in(x,i,));
}
if(!dis[x][i][]&&dis[y][i][]&&op==){
dis[x][i][]=; q.push(in(x,i,));
}
}
}
}
int main()
{
int N,M,u,v,Ca=; string A,B,C;
scanf("%d%d",&N,&M);
rep(i,,N){
cin>>A>>B>>C;
name(A); name(C);
if(B[]=='i') q.push(in(mp[A],mp[C],)),dis[mp[A]][mp[C]][]=;
else q.push(in(mp[A],mp[C],)),dis[mp[A]][mp[C]][]=;
}
DFS();
rep(i,,M){
cin>>A>>B>>C;
printf("Query %d: ",++Ca);
if(A==C&&B[]=='i') {puts("true"); continue;}
u=mp[A]; v=mp[C];
if(B[]=='i') {
if(dis[u][v][]) puts("true");
else puts("false");
}
else {
if(dis[u][v][]) puts("true");
else puts("false");
}
}
return ;
}

F .Keeping On Track

题意:给定一棵树,问删去一个点后,不连通的点最对有多少,在此基础上加一条边可以最多让多少对点对恢复连通。

思路:就是dfs一次,然后看所有儿子和父亲之上的连通块的大小; 第二问取最大的两个连通块连通即可。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int Laxt[maxn],Next[maxn],To[maxn];
int sz[maxn],q[maxn],cnt,ans,fcy,tot,N;
void add(int u,int v)
{
Next[++cnt]=Laxt[u];Laxt[u]=cnt;To[cnt]=v;
}
void dfs(int u,int f)
{
sz[u]=;
for(int i=Laxt[u];i;i=Next[i]){
if(To[i]!=f){
dfs(To[i],u);
sz[u]+=sz[To[i]];
}
}
tot=; q[++tot]=N+-sz[u];
for(int i=Laxt[u];i;i=Next[i])
if(To[i]!=f) q[++tot]=sz[To[i]];
sort(q+,q+tot+);
int sum=,tmp=;
rep(i,,tot) sum+=q[i];
rep(i,,tot) tmp+=(sum-q[i])*q[i];
tmp/=;
if(tmp>ans) ans=tmp,fcy=q[tot]*q[tot-];
else if(tmp==ans) fcy=max(fcy,q[tot]*q[tot-]);
}
int main()
{
int u,v;
scanf("%d",&N);
rep(i,,N) {
scanf("%d%d",&u,&v);
add(u,v); add(v,u);
}
dfs(,-);
printf("%d %d\n",ans,ans-fcy);
return ;
}

G .A Question of Ingestion

题意:一个人开始的饭量是M,如果今天吃饭了,第二天的饭量变为今天的2/3;如果今天不吃,第二天的饭量和昨天饭量一样(即恢复); 如果连续两天不吃,则第三天的饭量恢复到M。  现在给出N天的食物量, 问怎么吃可以迟到最多的食物。

思路:DP即可,dp[i][j]表示第i天的时候是连续第j天吃饭的最大食物量。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],f[maxn],dp[maxn][maxn],ans;
int main()
{
int N,M;
scanf("%d%d",&N,&M); f[]=M;
rep(i,,N) scanf("%d",&a[i]);
rep(i,,N) f[i]=f[i-]*/;
rep(i,,N){
rep(j,,i){
dp[i][j]=max(dp[i][j],dp[i-][j-]+min(f[j],a[i]));
if(i>)dp[i][j]=max(dp[i][j],dp[i-][j]+min(f[j],a[i]));
if(i>)dp[i][]=max(dp[i][],dp[i-][j]+min(f[],a[i]));
}
}
rep(i,,N) ans=max(ans,dp[N][i]);
printf("%d\n",ans);
return ;
}

H .Sheba's Amoebas

题意:问有几个连通块。

思路:DFS或者并查集即可。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn][maxn];
int fa[maxn*maxn],ans,N,M;
int x[]={,,,-,-,-,,};
int y[]={-,,,-,,,-,};
int find(int x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
void merge(int u,int v)
{
int fu=find(u),fv=find(v);
if(fu!=fv) fa[fu]=fv;
}
int main()
{
scanf("%d%d",&N,&M);
rep(i,,N*M) fa[i]=i;
rep(i,,N) scanf("%s",c[i]+);
rep(i,,N)
rep(j,,M){
if(c[i][j]=='#'){
rep(k,,){
if(i+x[k]>=&&i+x[k]<=N&&j+y[k]>=&&j+y[k]<=M&&c[i+x[k]][j+y[k]]=='#'){
merge((i-)*M+j,(i+x[k]-)*M+j+y[k]);
}
}
}
}
rep(i,,N)
rep(j,,M){
if(c[i][j]!='#') continue;
int t=(i-)*M+j;
if(find(t)==t) ans++;
}
printf("%d\n",ans);
return ;
}

太累了,后面了两个题先鸽了

Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)的更多相关文章

  1. 2017-2018 ACM-ICPC East Central North America Regional Contest (ECNA 2017) Solution

    A:Abstract Art 题意:给出n个多边形,求n个多边形分别的面积和,以及面积并 思路:模板 #include <bits/stdc++.h> using namespace st ...

  2. 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】

    任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...

  3. 2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) F 区间dp

    Problem F Removal GameBobby Roberts is totally bored in his algorithms class, so he’s developed a li ...

  4. [bfs,深度记录] East Central North America Regional Contest 2016 (ECNA 2016) D Lost in Translation

    Problem D Lost in Translation The word is out that you’ve just finished writing a book entitled How ...

  5. MPI Maelstrom(East Central North America 1996)(poj1502)

    MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercom ...

  6. poj 2732 Countdown(East Central North America 2005)

    题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http: ...

  7. East Central North America Region 2015

    E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 #include <iostream> #include <cstdio> #include <algo ...

  8. POJ 1240 Pre-Post-erous! && East Central North America 2002 (由前序后序遍历序列推出M叉树的种类)

    题目链接 问题描述 : We are all familiar with pre-order, in-order and post-order traversals of binary trees. ...

  9. POJ 1240 Pre-Post-erous! && East Central North America 2002 (由前序后序遍历序列推出M叉树的种类)

    题目链接:http://poj.org/problem?id=1240 本文链接:http://www.cnblogs.com/Ash-ly/p/5482520.html 题意: 通过一棵二叉树的中序 ...

随机推荐

  1. Qt Widgets——抽象滑块及其继承类

    三个可视类的默认外观分别如下(win7):它们的滑块都处于最小值0处. 理解QAbstractSlider时 可将它想成就是QScrollBar(该小部件的外观比较多地拥有QAbstractSlide ...

  2. js正则表达式取{}中的值

    var reg = /[^\{}]*\{(.*)\}[^\}]*/; var str = "1111{122}"; console.log(str.replace(reg,'$1' ...

  3. 转: Linux mount/unmount命令

    https://blog.csdn.net/okhymok/article/details/76616892 楼主具体哪里转的 我不清楚 好像没看到原始出处 开机自动挂载 如果我们想实现开机自动挂载某 ...

  4. 同步socket处理

    1.socket类是TCP通信的基本类,调用成员函数connect()可以连接到一个指定的通信端点,连接成功后用local_endpoint()和remote_endpoint()获得连接两端的端点信 ...

  5. linux系统用户和组管理

    用户和组管理 Linux是多用户多任务的网络操作系统,作为网络管理员,掌握用户的组的创建与管理至关重要. 学习要点: 了解用户和组的群的配置文件. 熟悉掌握Linux下用户的创建和维护管理. 熟悉掌握 ...

  6. 网卡驱动-BD详解(缓存描述符 Buffer Description)

    DMA介绍(BD的引入) 网络设备的核心处理模块是一个被称作 DMA(Direct Memory Access)的控制器,DMA 模块能够协助处理器处理数据收发.对于数据发送来说,它能够将组织好的数据 ...

  7. Daily record-June

    June201. Dear, wake up! Seven o'clock now, it's time to get up. Wash your face and to have breakfast ...

  8. C#中使用FFMPEG切割、合并视频。

    参考网址:https://blog.csdn.net/samwang_/article/details/70332924 使用前先确保电脑已经安装了FFMPEG,并且配置好环境变量.检测是否安装配置好 ...

  9. AVL平衡二叉树实现,图解分析,C++描述,完整可执行代码

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  10. Cracking The Coding Interview 9.3

    //Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log ...