山东省第四届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 ...
随机推荐
- 编程计算int类型整数的最大值和最小值
方法一:将一个int类型整数不断加1,加到最大值,再加1,就变成负值(最小值) 最大值就是除最高位外,其余位都为1,-1即是所有位全部是1,右移1位后最高位变0 最小值即是最高位为1,其余位为0, ...
- (浅谈).Net控件GridView绑定数据
前台GridView属性设置 <td> <asp:GridView ID="GridView" runat="server" AutoGene ...
- Servlet & JSP - UrlRewriteFilter
重写 URL 的好处有很多: 静态化页面,有利于搜索引擎收录. 隐藏真实的 URL,提高安全性. 当网站的结构发生变化时,无需要求用户修改书签. UrlRewriteFilter 的简单应用 1. M ...
- JMS - Message
一条 JMS 消息包含三个部分:消息头.消息属性和消息体. 消息头 消息头提供了和消息有关的元数据,它描述了消息有谁创建.何时创建.数据的有效长度等信息.消息头还包含了描述消息目的地(主题或队列)的路 ...
- Ehcache(2.9.x) - API Developer Guide, Transaction Support
About Transaction Support Transactions are supported in versions of Ehcache 2.0 and higher. The 2.3. ...
- HDOJ2025查找最大元素
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- vs2015启动iis express失败
vs2015启动web项目失败,查看日志 IIS Express\aspnetcore.dll 未能加载 ,解决方法 下载 VSorVWDASPNETCore.exe (https://www.asp ...
- PHP学习笔记--入门篇
PHP学习笔记--入门篇 一.Echo语句 1.格式 echo是PHP中的输出语句,可以把字符串输出(字符串用双引号括起来) 如下代码 <?php echo "Hello world! ...
- (转)一些国外优秀的elasticsearch使用案例
Github “Github使用Elasticsearch搜索20TB的数据,包括13亿的文件和1300亿行的代码” 这个不用介绍了吧,码农们都懂的,Github在2013年1月升级了他们的代码搜索, ...
- 基于AngularJS/Ionic框架开发的性能优化
AngularJS作为强大的前端MVVM框架,虽然已经做了很多的性能优化,但是我们开发过程中的不当使用还是会对性能产生巨大影响. 下面提出几点优化的方法: 1. 使用单次绑定符号{{::value}} ...