Educational Codeforces Round 29
A. Quasi-palindrome
题目链接:http://codeforces.com/contest/863/problem/A
题目意思:问一个数可不可以在不上一些前缀0以后变成一个回文数。
题目思路:暴力减掉后缀0,然后把剩余的部分暴力看一下是不是回文,如果是回文说明yes,否则no
代码:
//Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
const long long mod=1e9+;
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define endl "\n"
int main() {
ios::sync_with_stdio(false);cin.tie();
char s[];
cin>>s;
II len=strlen(s);
II r=len-;
for(II i=len-;i>=;i--){
if(s[i]=='') r--;
else break;
}
for(II i=,j=r;i<=j;i++,j--){
if(s[i]!=s[j]){
cout<<"NO"<<endl;
return ;
}
}
cout<<"YES"<<endl;
return ;
}
B. Kayaking
题目链接:http://codeforces.com/contest/863/problem/B
题目意思:现在有2n个人,n-1个可以装两个人的小皮艇,和两个只能装一个人的小皮艇,装两人的小船,如果两个人体重差太大,翻船值比较高,翻船值就是他们的绝对值,求最小的翻船值总和。
题目思路:我们考虑到n最大只有五十,所以我们可以暴力枚举挑出两个人去做一个人的小皮艇,然后剩下的人求翻船值,在这之前我们需要先排序。
代码:
/* ***********************************************
Author :xiaowuga
Created Time :2017年09月30日 星期六 22时39分17秒
File Name :Kayaking.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();
int n;
int a[];
cin>>n;
n*=;
for(int i=;i<n;i++) cin>>a[i];
sort(a,a+n);
int ans=inf;
for(int i=;i<n-;i++){
for(int j=i+;j<n;j++){
int sum=,t=-;
for(int k=;k<n;k++){
if(k==i||k==j) continue;
sum+=a[k]*t;
t*=-;
}
ans=min(ans,sum);
}
}
cout<<ans<<endl;
return ;
}
C. 1-2-3
题目意思:现在有两个机器人做类似石头剪刀布的游戏,(1打败3,3打败2,2打败1)现在给出k,a,b,三个数以及两个3*3的矩阵我们设其中一个为A,另一个为B,k表示比赛k轮,a,b表示两个机器人第一场出的数,两个矩阵表示,加入上一场两个机器人出了a,b,那么这一场,两个机器人会分别出A[a][b]和B[a][b],问k轮以后各自赢了多少局。
题目思路:首先这个肯定是会存在循环节的,而且循环节不会太长,估计最多也就十几,我们可以先求出循环节长度,找到完整的循环节数量,每个循环节中两个机器人各自赢的数量,和开始进入完整循环节前那一小部分的胜负情况,以及剩余的不满一个完整循环节的胜负情况。然后加在一块就对了,唯一注意的就是很有可能k小于进入进入完整循环节的次数,需要特判一下。
题目链接:http://codeforces.com/contest/863/problem/C
代码:
/* ***********************************************
Author :xiaowuga
Created Time :2017年10月01日 星期日 01时32分10秒
File Name :C.1-2-3.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int A[][],B[][];
int vis[][]={};
int ct[][]={};
int win[]={};
int main(){
ios::sync_with_stdio(false);cin.tie();
LL k;
int a,b;
cin>>k>>a>>b;
for(int i=;i<=;i++) for(int j=;j<=;j++) cin>>A[i][j];
for(int i=;i<=;i++) for(int j=;j<=;j++) cin>>B[i][j];
int c=;
int ta=a,tb=b,x,y;
vector<pair<int,int> >q;
while(){
c++;
if(vis[ta][tb]) break;
vis[ta][tb]=c;
q.push_back(make_pair(ta,tb));
x=ta;y=tb;
ta=A[x][y];
tb=B[x][y];
}
int cir=c-vis[ta][tb];
int lim=vis[ta][tb];
LL ansa=,ansb=;
if(k<lim){
for(int i=;i<k;i++){
x=q[i].first;y=q[i].second;
if(x==y) continue;
else if((x==&&y==)||(x==&&y==)||(x==&&y==)) ansa++;
else ansb++;
}
cout<<ansa<<' '<<ansb<<endl;
return ;
}
for(int i=;i<lim-;i++){
x=q[i].first;y=q[i].second;
if(x==y) continue;
else if((x==&&y==)||(x==&&y==)||(x==&&y==)) ansa++;
else ansb++;
}
vector<pair<int,int> >p;
int cta=,ctb=;
for(int i=lim-;i<q.size();i++){
x=q[i].first;y=q[i].second;
p.push_back(make_pair(x,y));
if(x==y) continue;
else if((x==&&y==)||(x==&&y==)||(x==&&y==)) cta++;
else ctb++;
}
LL t=(k-lim+)/cir,l=(k-lim+)%cir;
ansa+=t*cta;ansb+=t*ctb;
for(int i=;i<l;i++){
x=p[i].first;y=p[i].second;
if(x==y) continue;
else if((x==&&y==)||(x==&&y==)||(x==&&y==)) ansa++;
else ansb++;
}
cout<<ansa<<' '<<ansb<<endl;
return ;
}
D. Yet Another Array Queries Problem
题目链接:http://codeforces.com/contest/863/problem/D
题目意思:现在给一个数列,包含n个数,然后将要进行q次操作,q次操作之后进行m次询问,每次询问给予一个下标询问进行q此操作以后该下标位置的值是多少?
操作有两种:
1.比如12345 ,1-3轮转,变成23145,每个数变成自己右边的数,右边界的数,变成左边界的数。
2.区间翻转
题目思路:我们观察到m的数量是比较少,我们我们考虑反向推倒,找出这个下标在q次操作之前的下标是多少,就可以直接在原数组里面查询了,所以最大mq的复杂度就可以解决问题,观察数据我们发现这个复杂度是可行的。
代码:
/* ***********************************************
Author :xiaowuga
Created Time :2017年10月02日 星期一 09时12分59秒
File Name :text.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
#define second r
#define first l
const long long N=;
const long long mod=1e9+;
using namespace std;
struct node{
int l,r,id;
bool operator <(const node &m) const{
return l==r?r<m.r:l<m.l;
}
}tv[N];
int main(){
ios::sync_with_stdio(false);cin.tie();
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>tv[i].l>>tv[i].r;
tv[i].id=i;
}
sort(tv+,tv++n);
for(int i=;i<=n;i++){
if(tv[i].r<=tv[i-].r){
cout<<tv[i].id<<endl;
return ;
}
else if(tv[i].l<=tv[i-].l){
cout<<tv[i-].id<<endl;
return ;
}
tv[i].l=max(tv[i].l,tv[i-].r+);
}
cout<<-<<endl;
return ;
}
Educational Codeforces Round 29的更多相关文章
- E. Turn Off The TV Educational Codeforces Round 29
http://codeforces.com/contest/863/problem/E 注意细节 #include <cstdio> #include <cstdlib> #i ...
- Educational Codeforces Round 29(6/7)
1.Quasi-palindrome 题意:问一个字符串(你可以添加前导‘0’或不添加)是否是回文串 思路:将给定的字符串的前缀‘0’和后缀‘0’都去掉,然后看其是否为回文串 #include< ...
- Educational Codeforces Round 17
Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- (转)MFC鼠标单击消息拦截双击消息
如果LButtonDown和LButtonDblClk同时有实现的话 总会实现单击消息,在网上找解决方法,思想是在单击消息实现中取时间,计算两次单击事件的时间差 来回尝试修改,最后成这个样子,还算简单 ...
- 手动安装OpenStack Mistral
Prepare packages: $ sudo apt-get install python-dev python-setuptools python-pip libffi-dev libxslt1 ...
- 【Java NIO的深入研究1】缓冲区
缓冲区 传统的流和通道的对比 流 通道 慢 快 处理简单 处理复杂 单字节的传输 一块数据的传输 - Java.io.*已经重新写过 - 是对流的模拟 单向的 双向的 可直接访问 必须通过Buffer ...
- 第七章 使用 MyBatis API(MyBatis)
使用 MyBatis-Spring,你可以继续直接使用 MyBatis 的 API.仅仅在代码中使用 Spring 中的 SqlSessionFactoryBean 来创建一个 SqlSessionF ...
- hadoop3.1.0 window win7 基础环境搭建
https://blog.csdn.net/wsh596823919/article/details/80774805 hadoop3.1.0 window win7 基础环境搭建 前言:在windo ...
- OpenCV学习:播放avi视频文件
#if 0 //播放avi视频文件(IplImage) #include <opencv2/opencv.hpp> using namespace std; #pragma comment ...
- 总结一下前端面试题之Html和CSS
总结一下关于前端的面试题,今天我们分享关于Html和CSS部分的 面试 (1) 1. 常用那几种浏览器测试?有哪些内核(Layout Engine)? 2. 说下行内元素和块级元素的区别?行内块元素的 ...
- KAFKA安装+配置详解+常用操作+监控
http://blog.csdn.net/hadas_wang/article/details/50056381 http://qiyishi.blog.51cto.com/5731577/18575 ...
- Collabration Web Application Screenshot(English Language) Free download now!
The screenshots of english language version collabration web application which is as following: Incl ...
- 超全面的JavaWeb笔记day04<dom树等>
1.案例:在末尾添加节点(*****) 创建标签 createElement方法 创建文本 createTextNode方法 把文本添加到标签下面 appendChild方法 2.元素对象(了解) 如 ...