【刷题】AtCoder Regular Contest 003
A.GPA計算
题意:\(n\) 个人,一个字符串表示每个人的等第,每种等第对应一种分数。问平均分
做法:算
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=100+10;
int n,ans,val[]={4,3,2,1,0};
char s[MAXN];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
read(n);scanf("%s",s+1);
REP(i,1,n)ans+=val[s[i]-'A'];
printf("%.14f\n",(db)ans/n);
return 0;
}
B.さかさま辞書
题意:字符串按字典序从后往前排序
做法:reverse后sort就好了
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=100+10;
int n;
std::string s[MAXN];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
read(n);
REP(i,1,n)std::cin>>s[i],std::reverse(s[i].begin(),s[i].end());
std::sort(s+1,s+n+1);
REP(i,1,n)std::reverse(s[i].begin(),s[i].end()),std::cout<<s[i]<<'\n';
return 0;
}
C.暗闇帰り道
题意:给一个 \(n*m\) 的矩阵,每个位置上除起点、终点、障碍之外都有一个权值。
先在要从起点走到终点,不经过障碍。一步要一秒的时间,一条路径的价值是路径上所有位置价值的最小值。在 \(t\) 秒时,一个位置的价值是它的权值乘上 \(0.99^t\)
做法:从起点开始做要考虑时间问题,不够方便。于是从终点开始往回走。每走一步,记录的最小值乘上 \(0.99\) 与新到达的点的权值取min就好了
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=500+10;
const ld eps=1e-10;
int n,m,G[MAXN][MAXN],sx,sy,tx,ty,dr[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
ld V[MAXN][MAXN];
char s[MAXN];
struct node{
int x,y;
ld val;
};
std::queue<node> q;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
read(n);read(m);
REP(i,1,n)
{
scanf("%s",s+1);
REP(j,1,m)
if(s[j]=='s')sx=i,sy=j,G[i][j]=10;
else if(s[j]=='g')tx=i,ty=j,G[i][j]=10;
else if(s[j]=='#')G[i][j]=-1;
else G[i][j]=s[j]^'0';
}
REP(i,1,n)REP(j,1,m)V[i][j]=-1.0;
V[tx][ty]=10.0;
q.push((node){tx,ty,10.0});
while(!q.empty())
{
node pr=q.front();
q.pop();
int x=pr.x,y=pr.y;
ld now=pr.val*0.99;
REP(i,0,3)
{
int dx=x+dr[i][0],dy=y+dr[i][1];
if(dx<1||dx>n||dy<1||dy>m||G[dx][dy]==-1)continue;
ld nxt=min(now,(ld)G[dx][dy]);
if(nxt-V[dx][dy]>eps)V[dx][dy]=nxt,q.push((node){dx,dy,nxt});
}
}
if(V[sx][sy]==-1)puts("-1");
else printf("%.10Lf\n",V[sx][sy]);
return 0;
}
D.シャッフル席替え
题意:开始时,\(n\) 个人从小到大围坐在一个圆桌旁边。现在 \(K\) 次操作,每次
等概率选择两个人,将他们两个交换座位。给出 \(m\) 个限制,\(u\) 和 \(v\) 不能坐在一起。问 \(K\)次操作后满足所有限制的概率是多少。
做法:数据范围过小,所以多次rand后模拟就好了,做 \(2e6\) 次左右可以出误差较小的答案了
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
int n,m,k,Count=2e6,cnt,a[20],b[20],p[20],ps[20];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void rand_solve()
{
REP(i,0,n-1)p[i]=i;
REP(i,1,k)
{
int u=rand()%n,v=rand()%n;
if(u==v){--i;continue;}
std::swap(p[u],p[v]);
}
}
inline void calc_ans()
{
REP(i,0,n-1)ps[p[i]]=i;
REP(i,1,m)if(abs(ps[a[i]]-ps[b[i]])==1||abs(ps[a[i]]-ps[b[i]])==n-1)return ;
cnt++;
}
int main()
{
srand(time(0));
read(n);read(m);read(k);
REP(i,1,m)read(a[i]),read(b[i]);
REP(i,1,Count)rand_solve(),calc_ans();
printf("%.5f\n",(db)cnt/(db)Count);
return 0;
}
【刷题】AtCoder Regular Contest 003的更多相关文章
- AtCoder Regular Contest 151补题
AtCoder Regular Contest 151 A. Equal Hamming Distances 简单题,注意下答案需要字典序最小即可 #include<bits/stdc++.h& ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
- AtCoder Regular Contest 096
AtCoder Regular Contest 096 C - Many Medians 题意: 有A,B两种匹萨和三种购买方案,买一个A,买一个B,买半个A和半个B,花费分别为a,b,c. 求买X个 ...
- AtCoder Regular Contest 097
AtCoder Regular Contest 097 C - K-th Substring 题意: 求一个长度小于等于5000的字符串的第K小子串,相同子串算一个. K<=5. 分析: 一眼看 ...
- AtCoder Regular Contest 098
AtCoder Regular Contest 098 C - Attention 题意 给定一个只包含"E","W"字符串,可以花一的花费使他们互相转换.选定 ...
- Atcoder regular Contest 073(C - Sentou)
Atcoder regular Contest 073(C - Sentou) 传送门 每个人对开关的影响区间为a[i]--a[i]+t,因此此题即为将所有区间离散化后求所有独立区间的长度和 #inc ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
随机推荐
- 生成、查看文件的MD5、SHA、SHA256值
生成文件的MD5.SHA.SHA256 Linux系统生成MD5.SHA.SHA256 md5sum file1.zip >> MD5.txt sha1sum file1.zip > ...
- EF 事务(非分布式事务)
在EF 中怎么使用事务? 这个问题纠结了我好久,直到有人跟我一起讨论,我和同事一起讨论查资料. 查的好多资料都是使用 TransactionScope,用 TransactionScope 可处理分布 ...
- Intellij Idea 返回上次编辑快捷键设置
由于默认的返回上次编辑快捷键和和笔记本冲突. 需要从新设置快捷键. 找了好久终于找到了. 分别选中Back和Forward后设置新的快捷键即可
- Jlink使用技巧之烧写SPI Flash存储芯片
前言 大多数玩单片机的人都知道Jlink可以烧写Hex文件,作为ARM仿真调试器,但是知道能烧写SPI Flash的人应该不多,本篇文章将介绍如何使用JLink来烧写或者读取SPI Flash存储器, ...
- c#基础系列3---深入理解ref 和out
"大菜":源于自己刚踏入猿途混沌时起,自我感觉不是一般的菜,因而得名"大菜",于自身共勉. 扩展阅读 c#基础系列1---深入理解 值类型和引用类型 c#基础系 ...
- 网页录像录音功能的实现之MediaRecorder的使用
前面介绍了通过H5实现在网页内打开摄像头和麦克风,实现截图和图像预览的相关知识. getUserMedia API及HTML5 调用摄像头和麦克风 一个简单的demo 实现摄像头的调用及视频录制,截 ...
- Segment Occurrences(string find函数)
Description You are given two strings s and t, both consisting only of lowercase Latin letters.The s ...
- 作业20171026 alpha-2及alpha发布成绩
申诉 对成绩有疑问或不同意见的同学,请在群里[@杨贵福]. 申诉时间截止2017年11月21日 17:00. 成绩 scrum01 scrum02 scrum03 scrum04 scrum05 sc ...
- Linux内核分析——Linux内核学习总结
马悦+原创作品转载请注明出处+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 Linux内核学习总结 一 ...
- 同步手绘板——PC端实现画板
同步显示上设想通过bitmap传值再在web端显示,查阅资料发现有点难以实现,所以在web也生成一个画板,实现与android端类似功能,由android传递路径集合到web端显示.