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> ...
随机推荐
- IaaS,PaaS,SaaS 的区别和联系
原文:http://www.ruanyifeng.com/blog/2017/07/iaas-paas-saas.html 越来越多的软件,开始采用云服务. 云服务只是一个统称,可以分成三大类. Ia ...
- pandas的read_csv函数
pd.read_csv(filepath_or_buffer, sep=',', delimiter=None, header='infer', names=None, index_col=None, ...
- Hadoop恢复namenode数据
情景再现: 在修复hadoop集群某一个datanode无法启动的问题时,搜到有一个答案说要删除hdfs-site.xml中dfs.data.dir属性所配置的目录,再重新单独启动该datanode即 ...
- css常用字体
宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 Ming ...
- JS监听浏览器事件
Onunload与Onbeforeunload Onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过window.onunload来指定或 ...
- 大话java性能优化 pdf 下载(全本)
扫加公众号,回复”大话java性能优化",免费获取此书.
- 技术思维VS管理思维
以下为技术思维与管理思维的不同 在日常的工作中,会出现身兼两职 开发和项目经理 的情况,在此就要学会游刃有余的切换角色,方能一人分身二角 角色转换本质上是思维转换.思维决定一个人的行为,项目经理不像项 ...
- uva-10110
走廊上的灯1-n编号,一个人走过去,第i次走的时候,如果灯编号n%i=0,那么就把这个灯的开关摁一下,从最后一个灯返回到第一个灯不做任何操作,问最后一个灯最后是关还是开, 求完全平方数, 比如8,不存 ...
- Struts2:No result defined for action com.yibai.user.action.LoginAction and result input
转自:https://zhidao.baidu.com/question/133574016.html 1 String 里面有5个static 常量分别是: ERROR INPUT LOGIN NO ...
- 拒绝网页被 iframe 嵌套
在响应头里加一个X-Frame-Options DENY:浏览器拒绝当前页面加载任何Frame页面 SAMEORIGIN:frame页面的地址只能为同源域名下的页面 ALLOW-FROM origin ...