题目地址:http://codeforces.com/contest/493

A题

  写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可以再出现,但不能再参与计算,这里需要开一个flag数组判重 。打比赛时要调整好心态。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<cmath>
#include<algorithm>
#include<time.h> using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define LL long long
char sth[],sta[];
int num[][];
bool flag[][]; int main()
{
int t,ni,n,i;
char p1[],p2[],name[]; scanf("%s",sth);
scanf("%s",sta);
scanf("%d",&n);
clr(flag,); while(n--) {
scanf("%d%s%d%s",&t,p1,&ni,p2);
if(p2[]=='y') {
if(!num[ni][p1[]-'a']) {
num[ni][p1[]-'a']++;
} else {
if(!flag[ni][p1[]-'a']){
if(p1[]=='h') printf("%s ",sth);
else printf("%s ",sta);
printf("%d %d\n",ni,t);
flag[ni][p1[]-'a']=;
}
}
} else {
if(!flag[ni][p1[]-'a']){
if(p1[]=='h') printf("%s ",sth);
else printf("%s ",sta);
printf("%d %d\n",ni,t);
flag[ni][p1[]-'a']=;
}
}
} return ;
}

B题

  出现了一个 lexicographically greater的规则。读了很多遍题后才明白题意,其实就是比较两个序列的字典序,浪费了大量时间。首先比较得分大小,得分大的输出。得分相同则比较两个序列的字典序,如果字典序相同,最后一个是谁赢就输出谁。英语读题能力亟待提高。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<cmath>
#include<algorithm>
#include<time.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define LL long long const int N=*1e5+; int n,x;
int num1[N],num2[N],head1,head2;
LL sum1=,sum2=; int check(int a,int b)
{
int i;
int m=min(a,b);
for(int i=;i<=m;i++) {
if(num1[i]>num2[i]) {
puts("first");
exit();
}
if(num1[i]<num2[i]) {
puts("second");
exit();
}
} if(a>b) puts("first");
else {
if(a==b) {
if(x<) puts("second");
else puts("first");
}
if(a<b)
puts("second");
} } int main()
{
head1=; head2=;
scanf("%d",&n);
while(n--) {
cin>>x;
if(x>) {
head1++;
num1[head1]=x;
sum1+=x;
} else {
head2++;
num2[head2]=-x;
sum2+=-x;
}
} if(sum1!=sum2) {
if(sum1>sum2) puts("first");
else puts("second");
} else {
check(head1,head2);
} return ;
}

C题

二分查找三分线距离,使得一队得分减二队得分最大。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<cmath>
#include<algorithm>
#include<time.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define LL long long
const int N=2e5+;
int a[N],b[N],c[*N]; int main()
{
int n,m,p,t1,t2,s1,s2;
LL ret1,ret2,maxi=-1000000000LL;
scanf("%d",&n);
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
c[i]=a[i];
}
scanf("%d",&m);
for(int i=;i<m;i++) {
scanf("%d",&b[i]);
c[n+i]=b[i];
} sort(a,a+n);sort(b,b+m);sort(c,c+m+n+); for(int i=;i<n+m+;i++) {
p=c[i];
t1=upper_bound(a,a+n,p)-a;
s1=*t1+*(n-t1);
t2=upper_bound(b,b+m,p)-b;
s2=*t2+*(m-t2);
if(s1-s2>maxi) {
maxi=s1-s2;
ret1=s1;ret2=s2;
}
} cout<<ret1<<":"<<ret2<<endl; return ;
}

D题

  思维题。有一个N*N的棋盘(2 ≤ n ≤ 10^9) 左上角(1,1)有一个白皇后,右上角(1,n)一个黑色皇后,其它地方填满小兵。每次可以吃掉小兵或对方皇后。如果上下左右对角线相邻,则下一步就可以把对方吃掉。谁先吃掉对方皇后谁就赢。如果黑皇后赢,输出“black”,白皇后赢输出“white”,然后输出第一步走到的坐标(r,c)。If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c

  N分奇数和偶数两种情况讨论。两个人都采用最聪明的策略。每一步则想办法让对方是必败态。则棋手每次下完后保持与对方坐标距离(abs(x1-x2)+abs(y1-y2))是偶数即可。所以N为奇数,黑色赢;N为偶数,白色赢。综上规则,white赢时第一步走的坐标肯定是(1,2)

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<cmath>
#include<algorithm>
#include<time.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define LL long long int main()
{
int n; scanf("%d",&n);
if(n & ) puts("black");
else puts("white\n1 2"); return ;
}

Codeforces Round #281 (Div. 2) 解题报告的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  2. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  3. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  4. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  5. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  6. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  7. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  8. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  9. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. Mac实用技巧

    1. 程序员Mac新装机必备 Mac很玄这个大家都承认,但是鄙人觉得程序员用Mac才能真正发挥它的功效.下面就说说我的Mac使用: 基本编程软件:xcode,这个东西不仅仅是对mac的界面程序开发有用 ...

  2. ASP.NET中默认的一级目录

    默认一级目录结构: /Controllers – 存放负责处理 存放负责处理 URL请求的控制器类: 类:/Models – 存放表示和操纵数据以及业务对象的类: /Views – 存放负责呈现输出内 ...

  3. java,C#接口与C++的虚基类

    看C#的接口感觉就像C++中继承并实现虚基类的函数方法一样,是OOP编程中表现多态的一种方式.可以参考下面的文章: http://blog.sina.com.cn/s/blog_60ff8f1b010 ...

  4. AS3排序

    package { import flash.display.Sprite; public class Sort extends Sprite { private var arr:Vector.< ...

  5. http与https的区别以及https的加密原理

    HTTPS(Secure Hypertext Transfer Protocol)安全超文本传输协议 它是一个安全通信通道,它基于HTTP开发,用于在客户计算机和服务器之间交换信息.它使用安全套接字层 ...

  6. 栈和托管堆/值类型和引用类型/强制类型转换/装箱和拆箱[C#]

    原文地址:http://www.cnblogs.com/xy8.cn/articles/1227228.html 一.栈和托管堆      通用类型系统(CTS)区分两种基本类型:值类型和引用类型.它 ...

  7. Centos 6.5中安装后不能打开emacs的问题

    问题的发现过程: 安装了最新的centos版本后发现居然打不开emacs,然后在终端中输入emacs后还是不能打开,出现了下面的提示: emacs: error while loading share ...

  8. n%i之和

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1168 题意:给定一个n,注意这里n小于10^12,求 分析:早些时 ...

  9. 设置MATLAB中figure的背景为白色

    matlab的图形窗口每次背景都是灰色的,而我希望每次都是白色的背景,方便用图: 每次总是需要添加figure('color','w');或者figure('color',[1 1 1])或者set( ...

  10. C#生成带项目编号的Word段落

    using System; using Microsoft.Office.Interop.Word; using Word = Microsoft.Office.Interop.Word; names ...