【CodeForces】【#286】Div.2
T_T越来越水了,这次只做出A+B.
A题为了代码简单直接枚举(插入位置和插入字符)
//CF #286 Div.2 A
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
const int N=; void read(int &v){
v=;int sign=; char ch=getchar();
while(ch<'' || ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){v=v*+ch-''; ch=getchar();}
v*=sign;
}
/****************tamplate***********************/ string s,s1;
bool check(int pos,char ch){
s1="";
rep(i,pos) s1+=s[i];
s1+=ch;
F(i,pos,s.length()-) s1+=s[i]; for(int l=,r=s1.length()-;l<r;l++,r--)
if (s1[l]!=s1[r]) return ;
return ;
} int main(){
ios::sync_with_stdio(false);
cin >> s;
int l=,r=s.length(),pos=-; bool sign=;
F(i,,s.length())
rep(j,) if (check(i,j+'a')) {
cout <<s1<<endl;
return ;
}
printf("NA");
return ;
}
B题2B了一次,反正范围小,每种颜色的出边搜一遍就行了。
//CF #286 Div.2 B
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
const int N=; void read(int &v){
v=;int sign=; char ch=getchar();
while(ch<'' || ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){v=v*+ch-''; ch=getchar();}
v*=sign;
}
/****************tamplate***********************/
int n,m,cnt=;
struct edge{
int from,to,color;
};
vector<edge>E;
vector<int>G[N];
void add(int x,int y,int z){
E.pb((edge){x,y,z});
E.pb((edge){y,x,z});
int m=E.size();
G[x].pb(m-);
G[y].pb(m-);
} bool vis[N],yes[N];
void dfs(int x,int fa,int y,int col){
if (x==y) {yes[col]=; return;}
vis[x]=;
rep(i,G[x].size()){
edge&e=E[G[x][i]];
if (e.color==col && vis[e.to]==) dfs(e.to,x,y,col);
}
} int main(){
read(n); read(m);
int x,y,z;
F(i,,m){
read(x); read(y); read(z);
add(x,y,z);
}
int Q;
read(Q);
F(i,,Q){
read(x);
read(y);
memset(yes,,sizeof yes);
rep(i,G[x].size()){
memset(vis,,sizeof vis);
dfs(E[G[x][i]].to,x,y,E[G[x][i]].color);
}
int cnt=;
F(i,,m) cnt+=yes[i];
printf("%d\n",cnt);
}
return ;
}
【CodeForces】【#286】Div.2的更多相关文章
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意: 输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...
- 【Codeforces Round #438 C】 Qualification Rounds
[链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...
- 【Codeforces Round #438 B】Race Against Time
[链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...
- 【Codeforces Round #438 A】Bark to Unlock
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...
- 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry
C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$o ...
- 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼
目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...
- 【codeforces contest 1119 F】Niyaz and Small Degrees
题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
随机推荐
- 网站seo新手快速提升自己的技巧
第一.找自身的问题 大多数从业者都有下面两个严重的问题: 1.过于放大SEO的重要性每个人,都有自大的习惯,地位越NB往往越把自己认知的一切当做真理,其实有可能那只是井口那巴掌大的一片天.在网络营销中 ...
- 【学习笔记】【C语言】二维数组
1. 什么是二维数组 一个数组能表示一个班人的年龄,如果想表示很多班呢? 什么是二维数组?int ages[3][10]; 三个班,每个班10个人 相当于3行10列 相当于装着3个一维数组 二维数组是 ...
- spring注解中使用properties文件
一.只读取单个 properties 文件 1.在 spring 的配置文件中,加入 引入命名空间: xmlns:util="http://www.springframework.org/s ...
- "大哥,割草机借我用一下,我修整一下草坪。" ---- 谈谈this与JavaScript函数调用的不解之缘
在写上一篇有关apply和call的博文时(闲聊JS中的apply和call),起初我还是担心大家理解起来比较困难,因为要理解apply调用方式的前提是,至少先理解在JavaScript中函数调用是什 ...
- 数组的join()函数操作
join()函数的功能为:把数组的所有元素放入一个字符串,元素通过指定的分隔符分隔. 设置这样的数组操作 var a = []; a.push(1);a.push(3.1415926);a.push( ...
- 大饱眼福 7款类型各异的CSS3实用菜单
1.清新小图标的HTML5/CSS3侧边栏菜单 前我们分享过几款CSS3侧边栏菜单,像CSS3侧边栏菜单 带可爱的小图标菜单和CSS3侧边栏手风琴菜单,都非常不错.今天我们要分享的这款CSS3侧边栏菜 ...
- 解决grub引导错误的一次经历
我的电脑上一共是两块硬盘,1块固态硬盘(sda)装了win7,另外一块普通硬盘(sdb)装了ubuntu和centos两个系统,系统启动的引导是装在sdb上面的ubuntu的grub2,它负责选择不同 ...
- mysql 让一个存储过程定时作业的代码
1.在mysql 中建立一个数据库 test1 语句:create database test1 2.创建表examinfo create table examinfo( id int auto_in ...
- 常用的php数组排序函数
分享几个php数组排序函数,每个函数出去sort是排序的意思前缀字母的含义分别代表: a 索引 k 数组键 r 逆向 u 用户自定义 顺序排序函数 sort — 对数组排序 ksort — 对数组按 ...
- PHP实现根据浏览器跳转不同语言页面代码
以下是对使用PHP实现根据浏览器跳转不同语言页面的代码进行了介绍,需要的朋友可以过来参考下 代码: <?php /** * 根据不同浏览器跳转不同页面 * 来源:www.jbxue.com * ...