山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/
一、第J题坑爹大水题,模拟一下就行了
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,s,x,y,mod,i,p;
char team[],str[];
int cnt = ;
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
for(i=;i<n;i++)
{
scanf("%s%s%d%s",team,str,&p,str);
while()
{
if(p<=s-cnt)
{
cnt+=p;
printf("%d pages for %s\n",p,team);
break;
}
else
{
printf("%d pages for %s\n",s-cnt,team);
s = ((s*x)+y)%mod;
cnt = ;
}
}
}
putchar();
}
return ;
}
二、第I题概率DP问题
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std; double dp[][][];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
double a,b,c,d,e;
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
memset(dp,,sizeof(dp));
dp[][][] = ;
int i,j,k;
for(k=;k<=(n-)*;k++)
{
for(i=;i<=n;i++)
{
for(j=;j<=i;j++)
{
if(j-<&&i+<=n&&j+<=n)
{
dp[k][i+][j] += dp[k-][i][j]*a;
dp[k][i+][j+] += dp[k-][i][j]*b;
}
else if(j->=&&i+<=n&&j+<=n)
{
dp[k][i][j-] += dp[k-][i][j]*e;
dp[k][i+][j] += dp[k-][i][j]*c;
dp[k][i+][j+] += dp[k-][i][j]*d;
}
else if(j->=&&i==n)
{
dp[k][i][j-] += dp[k-][i][j];
}
}
}
}
double res = ;
for(i=;i<=*(n-);i++)
{
res+=dp[i][n][]*i;
}
printf("%.2lf\n",res);
}
return ;
}
三、第A题,向量旋转
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std; double xx1,yy1,xx2,yy2; int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%lf%lf%lf%lf",&xx1,&yy1,&xx2,&yy2);
double tx = xx2 - xx1;
double ty = yy2 - yy1; double x = tx*(1.0/2.0) - ty*(sqrt(3.0)/2.0) + xx1;
double y = ty*(1.0/2.0) + tx*(sqrt(3.0)/2.0) + yy1;
printf("(%.2lf,%.2lf)\n",x,y);
}
return ;
}
不会向量旋转,直接解方程方法做:
【code2】:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define exb 1e-6
#define PI acos(-1.0)
using namespace std;
struct node
{
double x,y;
}; double judge(node a ,node b)
{
return (a.x*b.y-a.y*b.x);
} double dist(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
double xx=(x1+x2)/2.0;
double yy=(y1+y2)/2.0;
double dd=dist(x1,y1,x2,y2);
if(fabs(y1-y2)<exb)
{
double yy1=y1+dd*sin(PI/3.0);
double yy2=y1-dd*sin(PI/3.0);
node ab,ac;
ab.x=x2-x1;
ab.y=y2-y1;
ac.x=xx-x1;
ac.y=yy1-y1; if(judge(ab,ac)>)
{
printf("(%.2f,%.2f)\n",xx,yy1);
}
else
{
printf("(%.2f,%.2f)\n",xx,yy2);
}
}
else
{
if(fabs(x1-x2)<exb)
{
double xx1=x1+dd*sin(PI/3.0);
double xx2=x1-dd*sin(PI/3.0);
node ab,ac;
ab.x=x2-x1;
ab.y=y2-y1;
ac.x=xx1-x1;
ac.y=yy-y1;
if(judge(ab,ac)>)
{
printf("(%.2f,%.2f)\n",xx1,yy);
}
else
{
printf("(%.2f,%.2f)\n",xx2,yy);
}
}
else
{
double k=-(x1-x2)/(y1-y2);
double pp=atan(k);
if(pp>PI/2.0)
pp=PI-pp;
k=tan(pp);
double b=yy-(k*xx);
double dd1=dd*sin(PI/3.0);
double xx1=sqrt(dd1*dd1/(k*k+1.0));
double yy1=k*xx1;
double xx2=-sqrt(dd1*dd1/(k*k+1.0));
double yy2=k*xx2;
node ab,ac;
ab.x=x2-x1;
ab.y=y2-y1;
ac.x=xx+xx1-x1;
ac.y=yy+yy1-y1;
if(judge(ab,ac)>)
{
printf("(%.2f,%.2f)\n",xx+xx1,yy+yy1);
}
else
printf("(%.2f,%.2f)\n",xx+xx2,yy+yy2);
}
}
}
return ;
}
四、第B题,听说可以暴力BFS过,我们队用的 强连通分量+缩点重构图+拓扑排序
Problem B:Thrall’s Dream
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 2005
#define M 10005
using namespace std;
struct edges
{
int u,v,next;
};
edges mye[M];
edges cj[M];
int head[N];
int myhead[N];
int cnt;
int cntcnt;
int cc,gg;
int dfn[N],low[N],Belong[N],Stap[N];
bool ff[N];
int visitNum,ct,Stop;
bool flag[N];
int id[N],od[N];
void addEdge(int x,int y)
{
mye[cnt].u=x;
mye[cnt].v=y;
mye[cnt].next=head[x];
head[x]=cnt++;
} void Add(int x,int y)
{
cj[cntcnt].u=x;
cj[cntcnt].v=y;
cj[cntcnt].next=myhead[x];
myhead[x]=cntcnt++;
} int n,m;
void init()
{
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head));
memset(myhead,-,sizeof(myhead));
cnt=;
cntcnt=;
for(int i=;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
addEdge(x,y);
}
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(Belong,,sizeof(Belong));
memset(Stap,,sizeof(Stap));
memset(flag,false,sizeof(flag));
memset(id,,sizeof(id));
memset(od,,sizeof(od)); } void tarjan(int i)
{
int y;
Stap[++Stop]=i;
flag[i]=true;
dfn[i]=low[i]=++visitNum;
for(int j=head[i];j!=-;j=mye[j].next)
{
y=mye[j].v;
if(!dfn[y])
{
flag[y]=true;
tarjan(y);
low[i]=min(low[i],low[y]);
}
else if(flag[y])
low[i]=min(low[i],dfn[y]);
}
if(low[i]==dfn[i])
{
ct++;
do
{
y=Stap[Stop--];
Belong[y]=ct;
flag[y]=false;
}while(y!=i);
}
} void dfs(int x,int len)
{
if(myhead[x]==- || len>=ct)
{
if(len>gg)
gg=len;
return;
}
for(int i=myhead[x];i!=-;i=cj[i].next)
{
int y=cj[i].v;
if(!ff[y])
{
ff[y]=true;
dfs(y,len+);
ff[y]=false;
}
}
}
void solve()
{
visitNum=ct=Stop=;
for(int i=;i<=n;i++)
{
if(!dfn[i])
tarjan(i);
}
if(ct==)
{
printf("Case %d: Kalimdor is just ahead\n",cc++);
return;
}
for(int i=;i<=n;i++)
{
for(int j=head[i];j!=-;j=mye[j].next)
{
int y=mye[j].v;
int u=Belong[i];
int v=Belong[y];
if(u!=v)
{
od[u]++;
id[v]++;
Add(u,v);
}
}
}
int ans1=,ans2=;
int temp=;
for(int i=;i<=ct;i++)
{
if(od[i]==)
{
ans1++;
}
if(id[i]==)
{
ans2++;
temp=i;
}
}
if(ans1> || ans2>)
{
printf("Case %d: The Burning Shadow consume us all\n",cc++);
return;
}
memset(ff,false,sizeof(ff));
gg=;
dfs(temp,);
if(gg!=ct)
{
printf("Case %d: The Burning Shadow consume us all\n",cc++); }
else
{
printf("Case %d: Kalimdor is just ahead\n",cc++);
}
return;
}
int main()
{
int t;
scanf("%d",&t);
cc=;
while(t--)
{
init();
solve();
}
return ;
}
五、F题
Problem F:Alice and Bob
【题解】:
给出一个多项式:(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1)
输入P,求X^p 前边的系数。
【code】:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[];
int main()
{
long long sb,p;
int t;
int n;
int q;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
int i;
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&q);
while(q--)
{
scanf("%lld",&p);
long long sb=;
for(i=;i<n&&p!=;i++)
{
if(p%==)
{
sb*=a[i];
sb%=;
}
p/=;
}
if(p==)
printf("%lld\n",sb);
else
printf("0\n");
}
}
}
return ;
}
六:E题
Problem E:Mountain Subsequences
【code】:
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
char sb[];
int dp[];
int ha[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,j,x;
long long max,s;
scanf("%s",sb);
memset(ha,,sizeof(ha));
for(i=;i<n;i++)
{
x=sb[i]-'a';
dp[i]=;
for(j=;j<x;j++)
{
dp[i]+=ha[j];
dp[i]%=;
}
ha[x]+=dp[i]+;
ha[x]%=;
}
/* for(i=n-1;i>=0;i--)
{
printf("%lld ",dp[i]);
}*/
// printf("\n");
max=;
memset(ha,,sizeof(ha));
for(i=n-;i>=;i--)
{
x=sb[i]-'a';
s=;
for(j=;j<x;j++)
{
s+=ha[j];
s%=;
}
ha[x]+=s+;
ha[x]%=;
max+=s*dp[i];
max%=;
// printf("%lld ",s);
}
//printf("\n");
printf("%lld\n",max);
}
return ;
}
七、H题
Problem H:Boring Counting
山东省第四届ACM大学生程序设计竞赛解题报告(部分)的更多相关文章
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...
- 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server
题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...
- 2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very ...
- UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树
Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/ ...
- 2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob
题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynom ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !
n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...
随机推荐
- 大表 update 方式
-- declare cursor cur_t is ; type tab_t is table of urowid index by binary_integer; l_rid tab_t; beg ...
- 看linux连接进程占用的实时流量iftop netatop NetHogs
因为新工厂的机器上面的业务混合部署非常严重,加上内网外网共用一个网卡(这个更不可思议),导致有时要定位一些进程流量的问题非常困难,所以最近花了点时间在网上搜集了一把 (aptitude search ...
- Tomcat发生异常
The Apache Tomcat Native library which allows optimal performance in production environments was not ...
- Jersey(1.19.1) - Sub-resources
@Path may be used on classes and such classes are referred to as root resource classes. @Path may al ...
- Ehcache(2.9.x) - API Developer Guide, Cache Decorators
About Cache Decorators Ehcache uses the Ehcache interface, of which Cache is an implementation. It i ...
- 【Ionic】---AngularJS扩展基本布局
目录: 标题栏 : ion-header-bar 页脚栏 : ion-footer-bar header/footer : 样式及内容 内容区 : ion-content 滚动框 : ion-scro ...
- SQL获取刚插入的记录的自动增长列ID的值
假设表结构如下: CREATE TABLE TestTable ( id int identity, CreatedDate datetime ) SQL2005获得新增行的自动增长列的语句如下: i ...
- Cocos2d-x中停止播放背景音乐
停止背景音乐播放代码放置到什么地方比较适合呢?例如:在HelloWorld场景中,主要代码如下: bool HelloWorld::init() { return true; } void Hello ...
- ios开发入门篇(二):Objective-C的简单语法介绍
一:面向对象的思想 objective-c与C语言的编程思想不同,C语言是面向过程的编程,而objective-c则是面向对象的编程,所谓面向对象,我个人的理解,就是抽象.将具有一定共同点的实物抽象成 ...
- (转)SqlServer数据库大型应用解决方案总结
随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的互联网应用,每天百万级甚至上亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的问题. 一 ...