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> ...
随机推荐
- 定义function的层级
不知道标题拟的对不对,今天犯了个错误,图一是正确的写法. 图一 为了代码可以重复利用,我把其中两个方法独立出来,如图二. 图二 后来发现运行错误,说Gxrc未定义,百思不得其解,后来琢磨了好久,才发现 ...
- win10的坑之wifi找不到
安装了win10一周以来,win10的坑太多太多,微软搞什么pc/mobile二合一,真是脑残行为. 首先是usb设备无缘无故找不到,据说是和杀毒软件/防火墙有关,后来是关掉了windows defe ...
- ECharts之饼图和柱形图demo
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Python print函数参数详解
官方文档 print(…) print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False) Prints the valu ...
- 对抗样本攻防战,清华大学TSAIL团队再获CAAD攻防赛第一
最近,在全球安全领域的殿堂级盛会 DEF CON 2018 上,GeekPwn 拉斯维加斯站举行了 CAAD CTF 邀请赛,六支由国内外顶级 AI 学者与研究院组成的队伍共同探讨以对抗训练为攻防手段 ...
- 洛谷::P1972 [SDOI2009]HH的项链
题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链 ...
- 数据库入门4 结构化查询语言SQL
知识内容: 1.了解SQL 2.库.表操作及索引 3.select语句及insert语句 4.update语句与delete语句 5.SQL常用函数 6.多表连接及组合查询 7.视图操作及数据控制 参 ...
- django的小操作,查询效率up, 引用art-template模板+djangorestframework
Part1: 提高查询效率newses = News.objects.select_related('category', 'author').get(id=1) # category和author字 ...
- 温故而知新-MySQL高级编程
1 load data infile语句 MySQL下的命令 登录mysql命令行模式 load data infile "/var/www/1.txt" into table ...
- spring securiry Xml 配置 登陆
参考:https://blog.csdn.net/yin380697242/article/details/51893397 https://blog.csdn.net/lee353086/artic ...