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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- MySQL常用shell语句
1.连接数据库 格式:mysql -h ip -P port -u user -p 2.修改某一列的值 格式:update tablename set column1 = 'xxx', column2 ...
- C API 连接MySQL及批量插入
CMySQLMgr.h: #ifndef _CMYSQLMGR_H_ #define _CMYSQLMGR_H_ #include <iostream> #include "my ...
- 安装cx_Oracle 遇到的杂项问题
1. 解决方法: 将xc用户添加进sudousers 2.安装VMware Tools 更新 http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2F ...
- webBrowser1.Document.Cookie取不到HttpOnly的Cookie,取Cookie不完整【转】
在做数据采集时,有些网站需要输入验证码,但各网站验证码都不同,不可能有完美的识别验证码的代码,所以我也没去研究,我所采取的方案是:在winform里通过WebBrowser调用网页先手动登录系统,然后 ...
- Golang - OSX配置VIM下的Golang开发环境 (MacOS为例)
测试环境 MacOS 10.12.6 首先安装VIM brew install vim 我已经安装了 Vim 8.0版本 然后安装 Vundle ,这是一个vim包管理器 git clone http ...
- php HTML安全过滤
/*HTML安全过滤*/ function _htmtocode($content) { $content = str_replace('%','%',$content); $content = s ...
- python改动文件内容,不须要read,write多个动作。
python 要改动文件内容,经常使用 是先read.后write , 再 rename.非常不爽. 比方:须要 把 yuv_dir ="../HD/" # &q ...
- js 停止事件冒泡 阻止浏览器的默认行为
在前端开发工作中,由于浏览器兼容性等问题,我们会经常用到“停止事件冒泡”和“阻止浏览器默认行为”. 浏览器默认行为: 在form中按回车键就会提交表单:单击鼠标右键就会弹出context menu. ...
- BDIP和BVLC纹理分析
Young Deok Chun 等人提出了基于 BVLC 矩和 BDIP 矩的一种纹理分析方法.BVLC 能显示粗糙和光滑特性,BDIP 能够很好的提取波谷和边缘.它们直接在彩色空间上进行处理,能有效 ...
- 把Excel中的数据转换成Sql语句
假如excel表格中有A.B.C三列数据,希望导入到数据库users表中,相应的字段各自是name,sex,age ,在你的excel表格中添加一列.利用excel的公式自己主动生成sql语句,方法例 ...