链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61581#overview

描写叙述:非常老的CF题,题不错,拿来训练正好。

做的时候刚做完BC,还时不时去hdu看看有木有judge结束,题有木有挂掉,脑子有点糊涂,当时过了三题(按自己平时做CF的顺序作的)。代码写得也非常繁琐(就记得B题T成狗,最后在群里的提醒下过了...)。当然如今脑子也是糊涂。打完北京赛区然后就要连续考试三门我也是醉了。

要不是立即比赛就要关了赛后AK的时间预计还要再往后拖他个几天...无论是不是退役这样的比赛确实是做一场少一场了,写个解题报告留个念吧。

题解:

A.Before
an Exam

题意:给出天数和总共要学习的小时数。而且给出每天能学习的最长时间和最短时间,问能不能正常完毕任务。

思路:直接找到上限下限看在不在当中就可以。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
//#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const LL MOD = 1000000007 ;
int Min[35],Max[35];
bool vis[35];
int n[35];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
int a,b;
scanf("%d%d",&a,&b);
int Lim_min=0,Lim_max=0;
for(int i=1;i<=a;i++)
{
scanf("%d%d",&Min[i],&Max[i]);
Lim_min+=Min[i];
Lim_max+=Max[i];
}
if(b>Lim_max||b<Lim_min)
puts("NO");
else
{
puts("YES");
for(int i =1;i<=a;i++)
{
//cout<<n[i]<<Min[i];
n[i]=Min[i];
//cout<<n[i]<<Min[i]<<endl;
}
int sub=b-Lim_min;
for(int i=1;i<=a;i++)
{
if(sub==0)
break;
else
{
//cout<<i<<" "<<Max[i]<<" "<<Min[i]<<" "<<n[i]<<endl;
//cout<<sub<<endl;
n[i]+=min(Max[i]-n[i],sub);
sub-=n[i]-Min[i];
}
}
for(int i=1;i<=a;i++)
if(i!=1)
printf(" %d",n[i]);
else printf("%d",n[i]);
printf("\n");
}
return 0;
}

B.The least round way

题意:给出一个n*n的矩阵(每一个点的值都是非负数),初始数值是1,从矩阵左上角走到矩阵右下角走出一条路径。把沿途的全部数都乘到自己身上,问最后后缀有多少个0。

思路:简单DP,从左上向右下推两次。第一次找到能够得到的2的最少数。第二次找到能够得到的5的最少数,两次推得的比較少的数量就是后缀0的最少数。

特殊情况是矩阵中存在0的情况,假设所得的最优路径上得到的后缀0数超过1个。那么就取经过0的路径。这样后缀0就仅仅有1个。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
//#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int M[1005][1005];
int a[1005][1005][2];
int dp2[1005][1005],dp5[1005][1005];
int from2[1005][1005],from5[1005][1005];//1是上。2是左
int main()
{
#ifdef LOCAL
freopen("out.txt", "r", stdin);
//freopen("in.txt", "w", stdout);
#endif
int t;
scanf("%d",&t);
bool flag = 0;
int tox = -1, toy= -1;
for(int i=0; i<t; i++)
for(int j=0; j<t; j++)
{
scanf("%d",&M[i][j]);
if(M[i][j]==0)
{
tox=i;
toy=j;
flag = 1;
} int ttt=M[i][j];
if(ttt!=0)
{
while(ttt%2==0&&ttt!=0)
{
a[i][j][0]++;
ttt/=2;
}
ttt=M[i][j];
while(ttt%5==0&&&ttt!=0)
{
a[i][j][1]++;
ttt/=5;
}
}
if(i==0&&j==0)
{
dp2[0][0]=a[0][0][0];
dp5[0][0]=a[0][0][1];
}
else
{
if(i==0)
{
dp2[i][j]=dp2[i][j-1]+a[i][j][0];
from2[i][j]=2;
}
else if(j==0)
{
dp2[i][j]=dp2[i-1][j]+a[i][j][0];
from2[i][j]=1;
}
else
{
if(dp2[i][j-1]<dp2[i-1][j])
{
dp2[i][j]=dp2[i][j-1]+a[i][j][0];
from2[i][j]=2;
}
else
{
dp2[i][j]=dp2[i-1][j]+a[i][j][0];
from2[i][j]=1;
}
}
if(i==0)
{
dp5[i][j]=dp5[i][j-1]+a[i][j][1];
from5[i][j]=2;
}
else if(j==0)
{
dp5[i][j]=dp5[i-1][j]+a[i][j][1];
from5[i][j]=1;
}
else
{
if(dp5[i][j-1]<dp5[i-1][j])
{
dp5[i][j]=dp5[i][j-1]+a[i][j][1];
from5[i][j]=2;
}
else
{
dp5[i][j]=dp5[i-1][j]+a[i][j][1];
from5[i][j]=1;
}
}
}
}
char ss[2005];
int top = 0;
if(dp2[t-1][t-1]<dp5[t-1][t-1])
{
if(flag == 1 && dp2[t-1][t-1]>1)
{
printf("1\n");
for(int i=0;i<tox;i++)
printf("D");
for(int i=1;i<t;i++)
printf("R");
for(int i=tox+1;i<t;i++)
printf("D");
return 0;
}
printf("%d\n",dp2[t-1][t-1]);
int row=t-1;
int col=t-1;
while(row||col)
{
if(from2[row][col]==2)
{
ss[top++]='R';
col--;
}
else
{
ss[top++]='D';
row--;
}
}
for(int i=top-1; i>=0; i--)
printf("%c",ss[i]);
}
else
{
if(flag == 1 && dp5[t-1][t-1]>1)
{
printf("1\n");
for(int i=0;i<tox;i++)
printf("D");
for(int i=1;i<t;i++)
printf("R");
for(int i=tox+1;i<t;i++)
printf("D");
return 0;
}
printf("%d\n",dp5[t-1][t-1]);
int row=t-1;
int col=t-1;
while(row||col)
{
if(from5[row][col]==2)
{
ss[top++]='R';
col--;
}
else
{
ss[top++]='D';
row--;
}
}
for(int i=top-1; i>=0; i--)
putchar(ss[i]);
}
return 0;
}

C.Tic-tac-toe

题意:给出一个棋盘(三子棋),给出棋盘的情况,'X'是第一个人的棋子。'0'是第二个人的棋子,'.'是空的。

来推断棋盘情况是否合法。假设合法,推断是否有人赢,假设没有人赢,假设没人赢且棋盘没满。则输出下一步谁走,否则输出平局。

思路:模拟搞搞搞。说一下我找到的最后一种情况吧,"XXX

00.

. . 0"是不合法的。

由于第一个人赢了,游戏就结束了,第二个人就不用下了。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
//#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
char ss[5][5];
int ac[3],ar[3],bc[3],br[3],ax[3],bx[3];
int judge()
{
if(ss[0][0]==ss[0][1]&&ss[0][0]==ss[0][2])
{
if(ss[0][0]=='X')
ar[0]=1;
else if(ss[0][0]=='0')
br[0]=1;
}
if(ss[1][0]==ss[1][1]&&ss[1][0]==ss[1][2])
{
if(ss[1][0]=='X')
ar[1]=1;
else if(ss[1][0]=='0')
br[1]=1;
}
if(ss[2][0]==ss[2][1]&&ss[2][0]==ss[2][2])
{
if(ss[2][0]=='X')
ar[2]=1;
else if(ss[2][0]=='0')
br[2]=1;
}
if(ss[0][0]==ss[1][0]&&ss[0][0]==ss[2][0])
{
if(ss[0][0]=='X')
ac[0]=1;
else if(ss[0][0]=='0')
bc[0]=1;
}
if(ss[0][1]==ss[1][1]&&ss[0][1]==ss[2][1])
{
if(ss[0][1]=='X')
ac[1]=1;
else if(ss[0][1]=='0')
bc[1]=1;
}
if(ss[0][2]==ss[1][2]&&ss[0][2]==ss[2][2])
{
if(ss[0][2]=='X')
ac[2]=1;
else if(ss[0][2]=='0')
bc[2]=1;
}
if(ss[0][0]==ss[1][1]&&ss[0][0]==ss[2][2])
{
if(ss[0][0]=='X')
ax[0]=1;
if(ss[0][0]=='0')
bx[0]=1;
}
if(ss[0][2]==ss[1][1]&&ss[2][0]==ss[1][1])
{
if(ss[0][2]=='X')
ax[1]=1;
if(ss[0][2]=='0')
bx[1]=1;
}
// for(int i=0;i<3;i++)
// cout<<ac[i]<<" "<<bc[i]<<" "<<ar[i]<<" "<<br[i]<<endl;
//cout<<ac[0]<<ac[1]<<ac[2]<<ar[0]<<ar[1]<<ar[2]<<ax[0]<<ax[1]<<" "<<bc[0]<<bc[1]<<bc[2]<<br[0]<<br[1]<<br[2]<<bx[0]<<bx[1]<<endl;
if(ac[0]+ac[1]+ac[2]+ar[0]+ar[1]+ar[2]+ax[0]+ax[1]>0&&bc[0]+bc[1]+bc[2]+br[0]+br[1]+br[2]+bx[0]+bx[1]>0)
return 3;
if(ac[0]+ac[1]+ac[2]>1)
return 3;
else if(bc[0]+bc[1]+bc[2]>1)
return 3;
else if(ar[0]+ar[1]+ar[2]>1)
return 3;
else if(br[0]+br[1]+br[2]>1)
return 3;
else if(ac[0]+ac[1]+ac[2]==1)
return 1;
else if(ar[0]+ar[1]+ar[2]==1)
return 1;
else if(br[0]+br[1]+br[2]==1)
return 2;
else if(bc[0]+bc[1]+bc[2]==1)
return 2;
else if(ax[0]+ax[1]>0)
return 1;
else if(bx[0]+bx[1]>0)
return 2;
return 0;
}
int main()
{
#ifdef LOCAL
//freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int aa=0,bb=0;
for(int i=0;i<3;i++)
scanf("%s",ss[i]);
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(ss[i][j]=='X')
aa++;
else if(ss[i][j]=='0')
bb++;
}
}
if(aa-bb>1||aa<bb)
puts("illegal");
else
{
if(aa+bb!=9)
{
int k=judge();
if(k==1)
{
if(aa>bb)
puts("the first player won");
else puts("illegal");
}
else if(k==2)
{
if(aa==bb)
puts("the second player won");
else puts("illegal");
}
else if(k==3)
puts("illegal");
else if(aa>bb)
puts("second");
else puts("first");
}
else
{ int k=judge();
if(aa!=5)
puts("illegal");
else if(k==1)
puts("the first player won");
else if(k==2)
puts("the second player won");
else if(k==3)
puts("illegal");
else puts("draw");
}
}
return 0;
}

D.

cid=61581#problem/D" style="color:blue; text-decoration:none; font-family:Verdana; font-size:13.63636302947998px; line-height:20px">Ancient Berland Circus

题意:给一个三个顶点,问以这三个点为顶点的正N边行(N<=100)的最小面积是多少。

思路:首先找到这个三角形的外切圆的圆心(正弦余弦定理),然后算出半径,然后从三角形開始枚举,到一百边形(边越少面积越小)。我居然由于开了100*100的数组越界RE。哈哈哈哈

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 13
#define PI acos(-1.0)
#define seed 31//131,1313
typedef long long LL;
using namespace std;
double corner[105][105] ;
double x[5],y[5];
void init()
{
for(int i = 3 ; i <= 100 ; i ++)
{
corner[i][1] = 2 * PI / (1.0 * i) ;
for(int j = 2 ; j <= i ; j ++)
{
//if(i<10)
corner[i][j]=corner[i][j-1]+corner[i][1];
//cout<<corner[i][j]<<" ";
}
//cout<<endl;
}
}
int main()
{
init();
for(int i = 0 ; i < 3 ; i ++)
{
cin>>x[i]>>y[i];
//cout<<x[i]<<" "<<y[i]<<endl;
}
double a = sqrt ( (x[1] - x[0])*(x[1] - x[0]) + (y[1] - y[0])*(y[1] - y[0]) ) ;
double b = sqrt ( (x[2] - x[0])*(x[2] - x[0]) + (y[2] - y[0])*(y[2] - y[0]) ) ;
double c = sqrt ( (x[2] - x[1])*(x[2] - x[1]) + (y[2] - y[1])*(y[2] - y[1]) ) ;
double cosa = (b * b + c * c - a * a) / (2 * b * c ) ;
double sina = sqrt (1 - cosa * cosa) ;
double r = a / (2 * sina) ;
double aa = asin (a / 2 / r) * 2 ;
double bb = asin (b / 2 / r) * 2 ;
double cc = asin (c / 2 / r) * 2 ;
//printf("%lf %lf %lf\n",aa,bb,cc);
int flag1 = 0 , flag2 = 0 , flag3 = 0;
for(int i = 3 ; i <= 100 ; i ++)
{
flag1 = 0 ;
flag2 = 0 ;
flag3 = 0 ;
for(int j = 1 ; j <= i ; j ++)
{
if(fabs(aa - corner[i][j])<1e-6)
flag1 = 1;
if(fabs(bb - corner[i][j])<1e-6)
flag2 = 1;
if(fabs(cc - corner[i][j])<1e-6)
flag3 = 1;
}
//printf("%d %d %d\n",flag1,flag2,flag3);
if(flag1 + flag2 + flag3 ==3)
{
//cout<< i << endl;
double s = 2 * PI / (1.0 * i) ;
double ledge = sqrt(r * r + r * r - 2 * r * r * cos (s));
//cout<<ledge<<endl;
double p = (r + r + ledge) / 2;
double ans = sqrt(p * (p - r) * (p - r) * (p - ledge)) * (1.0*i);
printf("%.8lf\n",ans);
break;
}
}
return 0;
}

E.

cid=61581#problem/E" style="color:blue; text-decoration:none; font-family:Verdana; font-size:13.63636302947998px; line-height:20px; background-color:rgb(226,228,255)">Least
Cost Bracket Sequence

题意:类似括号匹配的问题给出一个括号序列,中间存在问号。假设出现问号。能够选择将它变成‘(’或者‘)’,然后两种变形分别有所花费,问花费最少的能使全括号匹配的方式,不存在输出-1。

思路:从左到右每出现一个‘)’要保证它左边(包含本身)的’(‘数大于等于')’就可以。

这样每出现问号直接变成‘)’,假设出现不符合条件的情况就挑左边中一个能添加花费最少的‘?’变成‘(’。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 13
#define PI acos(-1.0)
#define seed 31//131,1313
//#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
char ss[500005];
struct Wenhao {
LL cost;
int pos;
}wenhao;
bool operator < (const Wenhao a,const Wenhao b)
{
return a.cost<b.cost;
}
priority_queue <Wenhao> q ;
int main()
{
scanf("%s",ss);
int len = strlen(ss);
int top = 0 ;
int res = 0 ;
LL ans = 0 ;
for(int i=0;i<len;i++)
{
if(ss[i]=='?')
{
res--;
LL a,b;
scanf("%lld%lld",&a,&b);
wenhao.cost = b - a ;
wenhao.pos = i;
q.push(wenhao);
ss[i] = ')';
ans += b ;
}
else if(ss[i]=='(')
res++;
else res--;
if(res<0)
{
if(!q.empty())
{
ans -= (q.top()).cost;
ss[q.top().pos] = '(';
q.pop();
res+=2;
}
else
{
puts("-1");
return 0;
}
}
}
if(res==0)
{
printf("%lld\n",ans);
puts(ss);
}
else puts("-1");
return 0;
}

CUGBACM Codeforces Tranning 1 题解的更多相关文章

  1. CUGBACM Codeforces Tranning 3 题解

    链接:http://acm.hust.edu.cn/vjudge/contest/view.action? cid=62515#overview 描写叙述:第三场CF训练了.这次做的挺搞笑的,我记得这 ...

  2. Codeforces Round #556 题解

    Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...

  3. Codeforces Round #569 题解

    Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...

  4. Codeforces Round #557 题解【更完了】

    Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...

  5. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  6. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  7. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  8. Codeforces Choosing Laptop 题解

    这题实在是太水了,具体看注释 蒟蒻的方法是一边找过时的电脑一边比大小 蒟蒻不才,只会C++ 其实还会free basic,但它已经过时了 附: 本题洛谷网址 Codeforces网址 希望蒟蒻的题解能 ...

  9. Codeforces 381 简要题解

    做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...

随机推荐

  1. SwitchOmega的详细配置——for Windows

    必看 先下载Shadowsocks客户端进行相应配置,然后只要对SwitchOmega 进行新建情景模式后简单配置即可. 本文不谈如何安装SwitchOmega只谈如何配置SwitchOmega 不会 ...

  2. eclipse 启动报share library load faild

      eclipse 与 jdk 版本要一致 *32 - 对应32位 *64 - 对应64位

  3. mysql 开启慢查询记录

    Linux查看mysql 安装路径 一.查看文件安装路径 由于软件安装的地方不止一个地方,所有先说查看文件安装的所有路径(地址). 这里以mysql为例.比如说我安装了mysql,但是不知道文件都安装 ...

  4. JSP 中的 Request 和 Response 对象

    客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应.它是HttpServletRequest类的实例:response对象包含了响应客户请求的有关信息,但在JSP中 ...

  5. iOS 获取沙盒文件路径及 写入/删除 沙盒文件

    出于安全考虑,iOS系统的沙盒机制规定每个应用都只能访问当前沙盒目录下面的文件(也有例外,比如系统通讯录能在用户授权的情况下被第三方应用访问),这个规则把iOS系统的封闭性展现的淋漓尽致. 一.沙盒中 ...

  6. java原生序列化和Kryo序列化性能比较

    简介 最近几年,各种新的高效序列化方式层出不穷,不断刷新序列化性能的上限,最典型的包括: 专门针对Java语言的:Kryo,FST等等 跨语言的:Protostuff,ProtoBuf,Thrift, ...

  7. PS_图象调整_太暗/过亮_曝光不足/过度

    对于曝光不足,图像太暗. 1.调整[色阶] 图象>调整>色阶   clrl+L 然后拖动"黑","灰","白"三个滑块. 2.使 ...

  8. 【Unity笔记】UGUI的Image、RawImage控件

    Image控件只能使用Sprite图片,RawImage通常使用Texture类型图片.项目设为2D模式后导入的图片Texture Type会自动转为Sprite. 没有选择源图片时,可以只选择颜色. ...

  9. Hadoop计算中的Shuffle过程(转)

    Hadoop计算中的Shuffle过程 作者:左坚 来源:清华万博 时间:2013-07-02 15:04:44.0 Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解Ma ...

  10. fullcalendar案例一<原>

    fullcalendar是个很强大的日历控件,可以用它进行排班.排会议.拍任务,很直观,用户体验良好. 看下效果图: #parse("index/head.vm") <lin ...