Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only)
http://codeforces.com/contest/12
A
水题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ string str[]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
for(int i=;i<;i++){
cin>>str[i];
}
for(int i=;i<;i++){
for(int j=;j<;j++){
if(str[i][j]!=str[-i][-j]){
cout<<"NO"<<endl;
return ;
}
}
}
cout<<"YES"<<endl; return ;
}
B
水题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ string str[];
int ch[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
string str1,str2,ans="";
cin>>str1>>str2;
for(int i=;i<str1.length();i++){
ch[str1[i]-'']++;
}
for(int i=;i<;i++){
if(ch[i]){
ans+=char(i+'');
ch[i]--;
break;
}
} for(int i=;i<;i++){
for(int j=;j<ch[i];j++){
ans+=char(i+'');
}
}
// cout<<ans<<" "<<str2<<endl;
if(ans==str2) cout<<"OK"<<endl;
else cout<<"WRONG_ANSWER"<<endl;
return ;
}
C
水题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m;
map<string,int>mp; int a[];
bool cmp1(int a,int b){
return a>b;
} bool cmp2(int a,int b){
return a<b;
} bool cmp(pair<int,string>a,pair<int,string>b){
return a.first>b.first;
} vector<pair<int,string> >ve; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
cin>>n>>m;
string str;
for(int i=;i<n;i++) cin>>a[i];
for(int i=;i<m;i++){
cin>>str;
mp[str]++;
}
map<string,int>::iterator it;
for(it=mp.begin();it!=mp.end();it++){
ve.push_back(make_pair(it->second,it->first));
}
sort(a,a+n,cmp2);
int ans1=,ans2=;
sort(ve.begin(),ve.end(),cmp);
/* for(int i=0;i<ve.size();i++){
cout<<ve[i].first<<" "<<ve[i].second<<endl;
}*/
for(int i=;i<ve.size();i++){
ans1+=ve[i].first*a[i];
}
sort(a,a+n,cmp1);
for(int i=;i<ve.size();i++){
ans2+=ve[i].first*a[i];
}
cout<<ans1<<" "<<ans2<<endl; }
D
线段树好题
题意:n个女性比三种属性,一旦有一个女的三种属性都被另一个女的压制,那这个女的会自杀,问多少女性会自杀
思路:
先按第一个属性从大到小严格排序,然后再把第二个属性离散化作为线段树的下标,最后再把第三个属性作为线段树上的值,然后查询最大值即可
如果第一个属性有相等的情况,需要把相等的情况全部比较完再更新
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define lson num<<1,s,mid
#define rson num<<1|1,mid+1,e
#define maxn 500005 using namespace std; struct node
{
int a,b,c;
bool operator < (const node &cmp)const
{
if(a!=cmp.a)return a<cmp.a;
if(b!=cmp.b)return b<cmp.b;
return c<cmp.c;
}
}wm[maxn]; int res[maxn<<];
int x[maxn]; void pushup(int num)
{
res[num]=max(res[num<<],res[num<<|]);
}
void build(int num,int s,int e)
{
res[num]=-;
if(s==e)return ;
int mid=(s+e)>>;
build(lson);build(rson);
}
void update(int num,int s,int e,int pos,int val)
{
if(s==e)
{
res[num]=max(res[num],val);
return;
}
int mid=(s+e)>>;
if(pos<=mid)update(lson,pos,val);
else update(rson,pos,val);
pushup(num);
}
int query(int num,int s,int e,int l,int r)
{
if(l<=s && r>=e)return res[num];
int mid=(s+e)>>;
if(r<=mid)return query(lson,l,r);
else if(l>mid)return query(rson,l,r);
else return max(query(lson,l,mid),query(rson,mid+,r));
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&wm[i].a);
for(int i=;i<=n;i++)
{
scanf("%d",&wm[i].b);
x[i]=wm[i].b;
}
for(int i=;i<=n;i++)
scanf("%d",&wm[i].c); sort(wm+,wm++n); sort(x+,x++n); int m=unique(x+,x++n)-x;
m--; int last=wm[n].a;
int r=n;
int l=n;
int ans=; wm[].a=0x3f3f3f3f; for(int i=n;i>=;)
{
while(wm[l].a==last)
{
l--;
}
int c=r;
while(c>l)
{
int pos=lower_bound(x+,x+m+,wm[c].b)-x;
if(pos+<=m && query(,,m,pos+,m)>wm[c].c)ans++;
c--;
}
c=r;
while(c>l)
{
int pos=lower_bound(x+,x+m+,wm[c].b)-x;
update(,,m,pos,wm[c].c);
c--;
}
i=l;r=l;last=wm[i].a;
}
printf("%d\n",ans);
return ;
}
E
构造题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int book[][]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n;
std::ios::sync_with_stdio(false);
cin>>n;
for(int i = ; i < n- ; i++){
for(int j = ; j < n- ; j++)
book[i][j] = (i+j)%(n-)+;
}
for(int i = ; i < n ; i++){
book[i][n-] = book[i][i];
book[n-][i] = book[i][i];
book[i][i] = ;
}
for(int i = ; i < n ; i++){
for(int j = ; j < n ; j++)
cout<<book[i][j]<<" ";
cout<<endl;
} }
Codeforces Beta Round #12 (Div 2 Only)的更多相关文章
- Codeforces Beta Round #12 (Div 2 Only) D. Ball sort/map
D. Ball Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/12/D D ...
- Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值
http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- HttpURLConnection连接超时问题
1.问题描述 这几天测试重构后的下载框架,发现在下载过程中如果网络中断或网络较差,个别应用的下载就会阻塞卡住,一直卡在 “正在下载 xx%”. 2.问题排查和定位 思考:网络差不应该报网络异常的错 ...
- Hive基础之Hive表常用操作
本案例使用的数据均来源于Oracle自带的emp和dept表 创建表 语法: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name ...
- linux 常规操作EOF写法梳理
在平时的运维工作中,我们经常会碰到这样一个场景:执行脚本的时候,需要往一个文件里自动输入N行内容.如果是少数的几行内容,还可以用echo追加方式,但如果是很多行,那么单纯用echo追加的方式就显得愚蠢 ...
- LRU的理解与Java实现
简介 LRU(Least Recently Used)直译为"最近最少使用".其实很多老外发明的词直译过来对于我们来说并不是特别好理解,甚至有些词并不在国人的思维模式之内,比如快速 ...
- tomcat启动原理
2018年04月12日 19:55:22 太极小帅帅 阅读数:282 前言 一直在用Tomcat,但是对其启动原理一直没去研究,这里准备去面试,可能会问道.于是总结了下启动原理.完全凭感觉去揣测, ...
- 代码: js日期
日期格式化 (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2015-11-16 08:09:04.423 (new Dat ...
- Springboot spring data jpa 多数据源的配置01
Springboot spring data jpa 多数据源的配置 (说明:这只是引入了多个数据源,他们各自管理各自的事务,并没有实现统一的事务控制) 例: user数据库 global 数据库 ...
- CSS 3栏自适应布局
绝对定位 css html,body{margin: 0px;height:100%;} div{height: 100%;} .left,.right {top: 0px;position: abs ...
- eclipse插件常用网址链接
目录 jar下载地址 java maven svn erMaster linux镜像ISO: http://www.linuxfly.org/post/659/ virtual下载: ...
- ubuntu sudo apt-get upgrade 和 sudo apt-get dist-upgrade区别
sudo apt-get upgrade: 不会对系统产生重大的影响,可以在任何时候运行. sudo apt-get dist-upgrade: 涉及核心的升级,通常会对系统功能产生实际的影响,可能在 ...