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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- e686. 显示打印窗口
The print dialog allows the user to change the default printer settings such as the default printer, ...
- win7语音识别开发(sapi)
参考:http://msdn.microsoft.com/en-us/library/ee125663(v=vs.85).aspx (sapi5.4 reference) http://msdn ...
- (转)typedef 函数指针的用法
typedef 函数指针的用法 在网上搜索函数指针,看到一个例子.开始没看懂,想放弃,可是转念一想,这个用法迟早要弄懂的,现在多花点时间看懂它,好过以后碰到了要再花一倍时间来弄懂它.其实很多时候都 ...
- bootstrap -- css -- 文字、列表
文字 <small></small>:呈现小号字体效果. <big></big>:程序大号字体效果 <abbr></abbr>: ...
- labview事件结构学习
编程的主要目的是为了实现用户的某种功能,用户通过用鼠标.键盘.程序内部等触发某种程序动作,从而达到某种结果,这些操作都被称作为事件,LabVIEW中相应这些事件最常用的结构就是“事件结构”.事件结构内 ...
- jQuery-处理css样式
1.css方法 获取匹配元素集合中的第一个元素的样式属性的值 或 设置每个匹配元素的一个或多个CSS属性 1)获取并设置单个css值 jQuery对象.css('css属性'); jQuery对象.c ...
- Ubuntu 安装 Oracle11gR2:'install' of makefile '/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'
网上包括官方,就是教给你如何安装依赖包什么的:libstdc++5,但很麻烦:既要下载找相关的包,还不一定能安装的上. 其实,仅仅是为了安装,直接从二进制的deb包里,解压一个 “libstdc++. ...
- 解决RaycastTarget勾选过多的烦恼
看过UGUI源码的朋友一定都知道,UI事件会在EventSystem在Update的Process触发.UGUI会遍历屏幕中所有RaycastTarget是true的UI,接着就会发射线,并且排序找到 ...
- conn.setAutoCommit(false)数据回滚设置
前言:介绍一点爱混淆的概念. 1.mysql中默认 autocommit=1:事物自动提交. 可通过 select @@autocommit;查看 但是是设置事务自动提交模式为set autocomm ...
- thinkjs——moment.js之前后台引入问题
前言: 工作中时常会遇见处理时间格式化问题:简言之就是将存在数据库中的时间戳的数字以“YYYY-MM-DD HH:mm:ss”格式展现出来. 过程: 1.在html文件中,通常是引入moment.js ...