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的更多相关文章

  1. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  2. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  3. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

  4. 【Codeforces Round #438 B】Race Against Time

    [链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...

  5. 【Codeforces Round #438 A】Bark to Unlock

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...

  6. 【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 ...

  7. 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼

    目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...

  8. 【codeforces contest 1119 F】Niyaz and Small Degrees

    题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...

  9. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  10. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

随机推荐

  1. 配置Rip的认证

      实验拓扑图 PS:我做实验使用的是DynamipsDUI模拟器,并且加载的是真实的ios镜像(c3745-advipservicesk9-mz.124-3c.bin) 1. 配置路由器R1 2. ...

  2. Collection 和 Collections的区别。

    Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...

  3. C#颜色 转换

    C#Winform 使用16进制颜色 var color = ColorTranslator.FromHtml("#eeeeee");

  4. RSA 加解密

    #region RSA public static byte[] GetBytes(String num) { BigInteger n = ); String s = n.ToString(); & ...

  5. OC4_XML文件解析

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-// ...

  6. OC10_代理反向传值

    // // ProtectedDelegate.h // OC10_代理反向传值 // // Created by zhangxueming on 15/6/24. // Copyright (c) ...

  7. (转)Yale CAS + .net Client 实现 SSO(4)

    第一部分:安装配置 Tomcat 第二部分:安装配置 CAS 第三部分:实现 ASP.NET WebForm Client 第四部分:实现基于数据库的身份验证 1.下载 Microsoft JDBC ...

  8. ResourceBundle和Properties(转载)

    转载: 一般来说,ResourceBundle类通常是用于针对不同的语言来使用的属性文件. 而如果你的应用程序中的属性文件只是一些配置,并不是针对多国语言的目的.那么使用Properties类就可以了 ...

  9. zynq 之u-boot

    u-boot 启动文件分析 u-boot首先执行的文件:C:\Users\summer_spinach\Desktop\zynq_linux相关\linux\uboot内核\u-boot-xarm\a ...

  10. 【Qt】Qt之自定义界面(实现无边框、可移动)【转】

    简述 UI设计是指对软件的人机交互.操作逻辑.界面美观的整体设计.好的UI设计不仅是让软件变得有个性.有品位,还要让软件的操作变得舒适简单.自由,充分体现软件的定位和特点. 爱美之心人皆有之.其实软件 ...