Coder-Strike 2014 - Finals (online edition, Div. 1)
CF 420A A. Start Up
题目链接:
http://codeforces.com/problemset/problem/420/A
题目意思:
给一个字符串A,通过镜面反射后得到A‘,推断A和A’是否全然一样。
解题思路:
水题。分析知有些字母通过镜面反射后和原来一样。
代码:
//#include<CSpreadSheet.h> #include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; #define Maxn 33
int hav[Maxn];
char save[110000]; void init()
{
memset(hav,0,sizeof(hav));
hav[1]=1,hav['H'-'A'+1]=1;
hav['I'-'A'+1]=1;
hav['M'-'A'+1]=1;
hav['O'-'A'+1]=1;
hav['T'-'A'+1]=1;
hav['U'-'A'+1]=1;
hav['V'-'A'+1]=1;
hav['W'-'A'+1]=1;
hav['X'-'A'+1]=1;
hav['Y'-'A'+1]=1; }
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%s",save+1))
{
int len=strlen(save+1);
int ans=1;
int p=1; init(); //printf("%d %d\n",p,len);
while(save[p]==save[len]&&p<=len)
{
if(!hav[save[p]-'A'+1])
{
ans=0;
break;
}
p++;
len--;
} if(p<=len)
ans=0;
if(ans)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
CF 420B B. Online Meeting
题目链接:
http://codeforces.com/problemset/problem/420/B
题目意思:
有n个人开会,已知按时间顺序的m个进出记录(部分开会),求哪些人可能一直在开会。
解题思路:
抽象模拟。
能够保存一个当前时间的统治者me.
(无)+(有)
(有)-(无)
详解请见代码:
//#include<CSpreadSheet.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; #define Maxn 110000 int ans[Maxn],add[Maxn];
int n,m,a,cnt,me;
char temp[3]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;i++)
ans[i]=1,add[i]=0;;
cnt=0;
me=0; for(int i=1;i<=m;i++)
{
scanf("%s%d",temp,&a);
if(*temp=='+')
{
if(!me||(me==a)) //更新统治者 注意要分别 +1 -1 +1的情况。此时统治者还是1
me=a;
else
ans[a]=0; //和前面的通知不一样 不行 比方+1 +2那么2不行
add[a]=1; //保存出现 if(a!=me&&!add[me]) //-1 +2 此时的1不行
ans[me]=0;
cnt++;
}
else //'-'
{
if(!me) //更新统治者
me=a;
if(a!=me&&add[a]==0) //+1 +2 -3 此时1为统治者
{
ans[me]=0;
me=a;
}
if(add[a]) //抵消
{
add[a]=0;
cnt--;
}
if(cnt) //还有剩余力量 +1 +2 -2 此时的2不行 +1 +2 -1此时的1也不行,仅仅要有+的不一样就不行
ans[a]=0; } }
int tt=0;
bool fi=true; for(int i=1;i<=n;i++)
if(ans[i])
tt++;
printf("%d\n",tt);
for(int i=1;i<=n;i++)
{
if(ans[i])
{
if(!fi) //第一个出现
printf(" ");
printf("%d",i);
if(fi)
fi=false;
} }
printf("\n"); }
return 0;
}
Codeforces 420C - Bug in Code
题目链接:
http://codeforces.com/problemset/problem/420/C
解题思路:
先预处理出当选中第i个人时,会使num[i]个人惬意。注意当(i,j)是某人同一时候讨厌的时候,假设此时选中(i,j)仅仅会使一个人惬意。所以先出于处理出这样的情况,直接推断出选中(i,j)时是否可行。假设不行提前减掉。 然后再排序,枚举选中的第一个人,直接二分出第二个人的位置。
代码:
//#include<CSpreadSheet.h> #include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; #define Maxn 310000 int num[Maxn],n,p;
map<pair<int,int>,int>myp; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d%d",&n,&p))
{
memset(num,0,sizeof(num));
myp.clear();
for(int i=1;i<=n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(a>b)
swap(a,b);
myp[make_pair(a,b)]++;
num[a]++;
num[b]++;
} map<pair<int,int>,int>::iterator it=myp.begin(); ll ans=0; for(;it!=myp.end();it++)
{
int ta=it->first.first,tb=it->first.second; if(num[ta]+num[tb]>=p&&num[ta]+num[tb]-it->second<p)
ans--; //说明选中ta和tb不可行
}
sort(num+1,num+n+1); for(int i=1;i<n;i++)
{
/* if(!num[i])
continue;*/
if(num[i]>=p)
{
ans+=n-i;
continue;
}
int temp=p-num[i];
if(temp>num[n]) //二分出第二个人的位置
continue;
int pos=lower_bound(num+i+1,num+n+1,temp)-num; ans+=n-pos+1;
//printf("i:%d pos:%d\n",i,pos); }
printf("%I64d\n",ans);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
Coder-Strike 2014 - Finals (online edition, Div. 1)的更多相关文章
- Coder-Strike 2014 - Finals (online edition, Div. 2) A. Pasha and Hamsters
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Coder-Strike 2014 - Finals (online edition, Div. 2) B. Start Up
需要满足的条件是 (1)每个字母是对称的 (2)每个字符串是对称的 #include <iostream> #include <algorithm> #include < ...
- Coder-Strike 2014 - Finals (online edition, Div. 2) C题
C. Online Meeting time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】
Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing
B. Bear and Compressing 题目链接 Problem - B - Codeforces Limak is a little polar bear. Polar bears h ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表
E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流
D. Delivery Bears 题目连接: http://www.codeforces.com/contest/653/problem/D Description Niwel is a littl ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力
C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...
随机推荐
- win-server下定时备份oracle数据库实现方法
1.在e盘建立一个“oracle_backup”的文件夹,文件夹下再建两个文件夹分别为:“new”,“old”,然后在oracle_backup文件夹中新建一个bat文件,取名“expdb.bat”, ...
- 使用Html5开发Android和iOS应用:HBuilder、Html5Plus、MUI
活动主题:五一巨献,问答有礼,105QB送给IT互联网界的劳动人民活动时间:4月30日晚上10点~5月2日晚上10点网址: http://ask.jiutianniao.com 2014年的时候,就 ...
- 开发自己的PHP MVC框架(一)
这个教程能够使大家掌握用mvc模式开发php应用的基本概念.此教程分为三个部分.如今这篇是第一部分. 如今市面上有非常多流行的框架供大家使用.可是我们也能够自己动手开发一个mvc框架.採用mvc模式能 ...
- Elasticsearch v5.4
在Windows上安装Elasticsearch v5.4.2 前言 最近项目里为了加快后台系统的搜索速度,决定接入开源的搜索引擎,于是大家都在对比较常用的几个开源做技术调研,比如Lucene+盘 ...
- echarts多条折线图和柱状图实现
参考链接:echarts官网:http://echarts.baidu.com/原型图(效果图): 图片.png 代码: <!DOCTYPE html> <html> < ...
- 【bzoj2453】维护队列 (分块 + 二分)
传送门(权限题) 题目分析 题意为:求区间内有多少种不同的数,带修改. 首先对原序列分块,用last[i]表示与i相同的上一个在哪里,然后将分块后的数组每个块内的按照last进行排序,这样查询时就可以 ...
- vector, list, deque的选用(vector适用少量对象,list适用大量对象),以及效率问题
如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面的原则: 1.如果你需要高效的随机存取,而不在乎插入和删除的效率,使用vector 2.如果你需要大量的插入和删除,而不关心随机存取( ...
- 空间同构(isomorphic)
1. introduction 对于一个 M22 矩阵空间,其 dimM22=4,基的构成如下: {(1000)(0010)(0100)(0001)} 则:M22≅R4 对于 P3 多项式空间,也即: ...
- 【20.00%】【codeforces 44G】Shooting Gallery
time limit per test5 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- android开发之微信支付功能的实现
移动开发中,支付类的App越来越多,对于开发者来说也是不可少的,不可不会的:下面就来说一说支付开发的流程 1.申请你的AppID 请到 开发者应用登记页面 进行登记,登记并选择移动应用进行设置后,将该 ...