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)的更多相关文章

  1. 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 ...

  2. Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值

    http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. Logstash之二:原理

    一.Logstash 介绍 Logstash 是一款强大的数据处理工具,它可以实现数据传输,格式处理,格式化输出,还有强大的插件功能,常用于日志处理. 二.工作流程 Logstash 工作的三个阶段: ...

  2. R语言学习——欧拉计划(3)Largest prime factor 求最大质因数

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

  3. CA单向认证和双向认证的区别?

    1:单向认证,内容会被串改吗?

  4. Windows 8的用户模式Shim Engine小探及利用

    转载: https://bbs.pediy.com/thread-175483.htm Windows Shim Engine,即Windows 兼容性模式实现引擎,在exe文件的属性对话框中有一个兼 ...

  5. Oracle创建数据库链接

    **********创建数据库链接******************create public database link link_gzzl connect to system identifie ...

  6. Windows环境下多版本JDK切换

    因为有切换多个版本的JDK需求,但是本机的JDK安装比较混乱(因为不是我最先使用的),所以出现了一些问题在这里记录下.本来我以为只需要修改环境变量中的JAVA_HOME环境路径即可,如果没有配置JAV ...

  7. python3 string

    字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello World!' var2 ...

  8. Django Middleware 之 SessionMiddleware

    Django版本:1.7.11 先放源码: class SessionMiddleware(object): def __init__(self): engine = import_module(se ...

  9. ORACLE中CONNECT BY...START WITH...的使用

    源: https://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm http://www.cnblogs.com/baiy ...

  10. uva-167-枚举

    题意:八皇后问题,要求选取的总和最大 #include<stdio.h> #include<iostream> #include<sstream> #include ...