Codeforces Beta Round #55 (Div. 2)
Codeforces Beta Round #55 (Div. 2)
http://codeforces.com/contest/59
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 pb push_back
- #define eb emplace_back
- #define maxn 1000005
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- string str;
- cin>>str;
- int big=,small=;
- for(int i=;i<str.length();i++){
- if(str[i]>='A'&&str[i]<='Z'){
- big++;
- }
- else{
- small++;
- }
- }
- if(big<=small){
- for(int i=;i<str.length();i++){
- if(str[i]>='A'&&str[i]<='Z'){
- str[i]+=;
- }
- cout<<str[i];
- }
- }
- else{
- for(int i=;i<str.length();i++){
- if(str[i]>='a'&&str[i]<='z'){
- str[i]-=;
- }
- cout<<str[i];
- }
- }
- }
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 pb push_back
- #define eb emplace_back
- #define maxn 1000005
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int a[];
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- cin>>n;
- int ans=;
- int sum=;
- int ji=0x3f3f3f3f,ou=0x3f3f3f3f;
- for(int i=;i<=n;i++){
- cin>>a[i];
- if(a[i]%&&a[i]<ji) ji=a[i];
- if((a[i]%==)&&a[i]<ou) ou=a[i];
- sum+=a[i];
- }
- if(sum%)cout<<sum<<endl;
- else{
- if(ji!=0x3f3f3f3f) cout<<sum-ji<<endl;
- else cout<<<<endl;
- }
- }
C
模拟,找出前str.length()/2中,str[i]=='?'&&str[str.length()-1-i]=='?'的个数,然后贪心
- #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 pb push_back
- #define eb emplace_back
- #define maxn 1000005
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- map<char,int>mp;
- string str;
- cin>>n>>str;
- int prex=,prey=;
- int num=;
- rep(i,,str.length()){
- if(str[i]!='?')
- mp[str[i]]=;
- }
- int len=str.length()+;
- int L=len-;
- len/=;
- rep(i,,len){
- if(str[i]=='?'&&str[L-i-]=='?') num++;
- }
- int k=n-mp.size();
- rep(i,,len){
- if(num<k){
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- if(i==L-i-){
- if(str[i]=='?'){
- if(num->=k){
- if(mp['a']){
- str[i]='a';
- num--;
- }
- else{
- str[i]='a';
- mp['a']=;
- num--;
- k--;
- }
- }
- else if(num->=k-){
- int flag=;
- rep(j,,){
- if(mp[char(j+'a')]==){
- mp[char(j+'a')]=;
- num--;
- k--;
- str[i]=char(j+'a');
- flag=;
- break;
- }
- }
- if(flag){
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- else{
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- }
- else if(str[i]=='?'&&str[L-i-]!='?'){
- str[i]=str[L-i-];
- }
- else if(str[i]!='?'&&str[L-i-]=='?'){
- str[L-i-]=str[i];
- }
- else if(str[i]=='?'&&str[L-i-]=='?'){
- prex=i,prey=L-i-;
- if(num->=k){
- if(mp['a']){
- str[i]='a';
- str[L-i-]='a';
- num-=;
- }
- else{
- mp['a']=;
- k--;
- num-=;
- str[i]='a';
- str[L-i-]='a';
- }
- }
- else if(num->=k-){
- int flag=;
- rep(j,,){
- if(mp[char(j+'a')]==){
- mp[char(j+'a')]=;
- k--;
- num-=;
- str[i]=char(j+'a');
- str[L-i-]=char(j+'a');
- flag=;
- break;
- }
- }
- if(flag){
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- else{
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- else if(str[i]!='?'&&str[L-i-]!='?'){
- if(str[i]!=str[L-i-]){
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- }
- // cout<<k<<endl;
- // cout<<prex<<" "<<prey<<endl;
- if(k==){
- int flag=;
- rep(i,,){
- if(mp[char(i+'a')]==){
- str[prex]=char(i+'a');
- str[prey]=char(i+'a');
- flag=;
- break;
- k--;
- }
- }
- if(flag){
- cout<<"IMPOSSIBLE"<<endl;
- return ;
- }
- }
- cout<<str<<endl;
- }
D
模拟
- #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 pb push_back
- #define eb emplace_back
- #define maxn 1000005
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- int a[],b[];
- int book[];
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- cin>>n;
- rep(i,,*n) cin>>b[i];
- rep(i,,*n) cin>>a[i];
- int k;
- cin>>k;
- int pos=,group,pp=;
- while(a[pos]!=k) pos++;
- group=pos/+;
- rep(i,,*(group-)) book[a[i]]=true;
- rep(i,,*n) if(!book[b[i]]){
- pp=i;break;
- }
- if(a[pos]!=b[pp]) sort(a,a+*n);
- else{
- int flag=-;
- rep(i,*(group-),*group) if(i!=pos) flag=max(flag,a[i]);
- sort(a,a+*group);
- int pos=;
- while(a[pos]!=flag) pos++;
- sort(a+pos+,a+*n);
- }
- rep(i,,*n) if(a[i]!=k) cout<<a[i]<<" ";
- }
E
用bfs找最短路,book[i][j]表示当前走到j,它的前一步是在i位置,然后book[i][j]记录的是它的前一步在队列中的位置
- #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 pb push_back
- #define eb emplace_back
- #define maxn 1000005
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- vector<int>ve[];
- int book[][];
- int n,m,k;
- set< pair<int,pair<int,int> > >se;
- set< pair<int,pair<int,int> > >::iterator it;
- struct sair{
- int pre,now,step;
- }Q[];
- int bfs(){
- sair s,e;
- s.pre=,s.now=,s.step=;
- int L=,R=;
- Q[R++]=s;
- int u;
- while(L<R){
- s=Q[L++];
- rep(i,,ve[s.now].size()){
- u=ve[s.now][i];
- if(!book[s.now][u]){
- it=se.find(make_pair(s.pre,make_pair(s.now,u)));
- if(it==se.end()){
- e.pre=s.now;
- e.now=u;
- e.step=s.step+;
- book[e.pre][e.now]=L-;
- Q[R++]=e;
- if(u==n){
- cout<<e.step<<endl;
- return R-;
- }
- }
- }
- }
- }
- return ;
- }
- void dfs(int pos){
- if(pos==) exit();
- if(pos==){
- cout<<Q[pos].now<<" ";
- return;
- }
- dfs(book[Q[pos].pre][Q[pos].now]);
- cout<<Q[pos].now<<" ";
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- cin>>n>>m>>k;
- int u,v;
- rep(i,,m){
- cin>>u>>v;
- ve[u].pb(v);
- ve[v].pb(u);
- }
- int w;
- rep(i,,k){
- cin>>u>>v>>w;
- se.insert(make_pair(u,make_pair(v,w)));
- }
- int pos=bfs();
- if(!pos) cout<<-<<endl;
- else{
- dfs(pos);
- }
- }
Codeforces Beta Round #55 (Div. 2)的更多相关文章
- 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> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- Redis 密码
- Navicat Premium 12安装与激活
https://www.jianshu.com/p/42a33b0dda9c 若使用Navicat Premium 12.1.10.0请转至Navicat Premium 12.1.10.0安装与激活 ...
- Cache专用: SoftReference
SoftReference的语义就是当内存不够用的时候,GC会回收SoftReference所引用的对象.所以,在memory sensitive的程序中将某些大型数据设置成SoftReference ...
- 机器学习进阶-图像金字塔与轮廓检测-轮廓检测 1.cv2.cvtColor(图像颜色转换) 2.cv2.findContours(找出图像的轮廓) 3.cv2.drawContours(画出图像轮廓) 4.cv2.contourArea(轮廓面积) 5.cv2.arcLength(轮廓周长) 6.cv2.aprroxPloyDP(获得轮廓近似) 7.cv2.boudingrect(外接圆)..
1. cv2.cvtcolor(img, cv2.COLOR_BGR2GRAY) # 将彩色图转换为灰度图 参数说明: img表示输入的图片, cv2.COLOR_BGR2GRAY表示颜色的变换形式 ...
- 2018SDIBT_国庆个人第二场
A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...
- 1:python 简介与基础
什么是python? 1.python是一种面向对象的解释型语言,它继承了传统编译语言的通用性和强大性,同时也借鉴了简单脚本和解释语言的易用性. 2.python 在自动化测试.人工智能.数据分析等方 ...
- [C语言]变量VS常量
-------------------------------------------------------------------------------------------- 1. 固定不变 ...
- Ajax 学习 第四篇
使用jQuery实现Ajax 跨域
- ubuntu16.04 64bit 升级到 python3.6
https://blog.csdn.net/zhao__zhen/article/details/81584933 https://www.codetd.com/article/1967538 htt ...
- linux下的arm汇编程序
1.gnu 的编译环境搭建 解压编译工具,加入环境变量PATH 2.编译相关命令的使用 编译命令 arm-linux-gcc -g -c -o led.o main.o led.c main.c / ...