A.ABBA

题意:就是问你一个矩阵能由几个行向量表示出来

Solution

其实就是求矩阵的秩,但是会被卡精度(被卡了好几发),直接抄个矩阵求秩的板子就AC了

Code
#define CLR(x) memset(x,0,sizeof(x))//定义宏
using namespace std;
double mat[300][300];//定义矩阵
int r,c;
int cmp(double x,double y){
double v = x - y;
if(v > 1e-1) return 1;//1e-1表示10^-1
if(v < -1e-1) return -1;
return 0;
}
//乘相应值
void subrow(int r1 , int r2,double temp){
for(int i = 1 ; i <= c ; i++){
mat[r1][i] -= mat[r2][i]*temp;
}
}
//交换数值
void swaprow(int r1 , int r2){
for(int i = 1 ; i <= c ; i++){
swap(mat[r1][i],mat[r2][i]);
}
}
//判断秩(主要判定函数)
void solve() {
for (int i = 1; i <= r; i++) {
for (int cal = i; cal <= c; cal++) { //对这 i 行的每一列来找,要是这列本身和之下的列全是0,则找 i 行下一列。
bool flag = true;
if (cmp(mat[i][cal], 0) == 0) {
flag = false; //如果第 i 行 cal 列这个位置是 0 ,那找找这列下面的行有没有
for (int j = i + 1; j <= r; j++) { //一个不为 0 的数 , 要是有 , 就将它与 i 行交换。
int tmp = cmp(mat[j][cal], 0);
if (tmp == 1 || tmp == -1) {
flag = true;
swaprow(j, i);
break;
}
}
}
if (!flag) continue;//如果这列全是 0 , 到下一列。
int v = i; //如果发现这列有值不为 0 并把它跟 i 行交换后,
int maxn = mat[i][cal]; //就再找这列有没有比 i 行 这个位置的值更大的值,如果有,将那一行
for (int j = i + 1; j <= r; j++) { //跟i行交换。(听说是为了减小误差)
if (cmp(mat[j][cal], mat[i][cal]) == 1) {
v = j;
maxn = mat[j][cal];
}
}
if (v != i) {
swaprow(i, v);
}
for (int j = 1; j <= r; j++) {
if (j == i) continue;
if (cmp(mat[i][cal], 0) == 0) continue;
double tmp = mat[j][cal] / mat[i][cal];
subrow(j, i, tmp);
}
break;
}
}
}
int main() {
CLR(mat);
scanf("%d %d", &r, &c);
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
scanf("%lf", &mat[i][j]);
}
}
solve();
bool f = false;
int ans = 0;
for (int i = r; i >= 1; i--) {
for (int j = 1; j <= c; j++) {
int tmp = cmp(mat[i][j], 0);
if (tmp == 1 || tmp == -1) {
f = true;
break;
}
}
if (f) {
ans = i;
break;
}
}
printf("%d\n", ans);//输出秩
return 0;
}

E.Elvis Presley

题意:
在形如二叉树的DAG上选出一个包含a,b的极大点集,使这些点互不可达,且选的个数最少

Solution

阅读理解题

Code

int main() {
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
if (a == 1) {
cout << -1;
return 0;
}
set stt;
int now = a;
while (now) {
stt.insert(now);
now /= 2;
}
now = b;
int lca;
while (now) {
if (stt.find(now) != stt.end()) {
if (now == a) {
cout << -1;
return 0;
}
lca = now;
break;
}
now /= 2;
}
now = b;
vector ans;
while (now / 2 != lca) {
if (now % 2) ans.push_back(now / 2 * 2);
else ans.push_back(now / 2 * 2 + 1);
now /= 2;
}
now = a;
while (now / 2 != lca) {
if (now % 2) ans.push_back(now / 2 * 2);
else ans.push_back(now / 2 * 2 + 1);
now /= 2;
}
now = lca;
while (now != 1) {
if (now % 2) ans.push_back(now / 2 * 2);
else ans.push_back(now / 2 * 2 + 1);
now /= 2;
}
ans.push_back(a), ans.push_back(b);
sort(ans.begin(), ans.end());
for (int i: ans) cout << i << " ";
}

G.Green Day

题意:略

Solution

题解:仿样例,凑出来的,神奇的AC姿势

Code
void solve() {
int k;
cin >> k;
cout<< 2*k << endl;
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= k; ++j) {
cout << i << " " << i + j<< endl;
}
for (int j = k+1 ; j <= 2 * k-1 ; ++j) {
cout << i + k << " " << (i + j-1)%(2*k)+1 << endl;
}
}
}

J. Burnished Security Updates

题意:给定一棵边权为小写字母的树和一个目标串$S$ , 问是否存在一条简单路径,使S成为该路径构成的字符串的子序列。若存在,输出任何一条合法路径的两个端点$($先起点,后终点$)$ ,否则输出-1 -1。

Solution

思路:
​ 树形dp维护以某个节点为根的子树中,以根为路径的一个端点,可以在$S$ 中匹配的最长前缀和后缀。当某棵子树的前后缀已经覆盖了$S$,并且前后缀的路径不重复,就是合法路径。保证不重复的方法详见代码。

Code
int n, m, idx;
string s;
int head[maxn];
pii st[maxn], ed[maxn], ans;
struct Edge {
int to, nxt; char c;
} edge[maxn * 2];
void addedge(int u, int v, char c) {
edge[idx] = {v, head[u], c};
head[u] = idx ++;
edge[idx] = {u, head[v], c};
head[v] = idx ++;
}
void dfs(int u, int fa) {
st[u] = ed[u] = {0, u};
for(int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].to; char c = edge[i].c;
if(v == fa) continue;
dfs(v, u);
if(c == s[st[v].x + 1] && st[v].x < m) st[v].x ++;
if(c == s[m - ed[v].x] && ed[v].x < m) ed[v].x ++;
// 路径不重复
if(st[u].x + ed[v].x >= m) ans = {st[u].y, ed[v].y};
if(ed[u].x + st[v].x >= m) ans = {st[v].y, ed[u].y};
st[u] = max(st[u], st[v]);
ed[u] = max(ed[u], ed[v]);
}
}
int main() {
ios;
cin >> n >> m;
for(int i = 1; i <= n; i ++) head[i] = -1;
for(int i = 1; i < n; i ++) {
int u, v; char c;
cin >> u >> v >> c;
addedge(u, v, c);
}
cin >> s;
s = "?" + s;
ans = {-1, -1};
dfs(1, 0);
cout << ans.x << " " << ans.y;
}

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(74)-微信公众平台开发-自定义菜单
  2. IIS6与IIS7中如何设置文件过期
  3. 关于TCP/IP的三次握手和四次挥手解释
  4. WPF超级链接
  5. ASP.NET MVC5 插件化机制简单实现
  6. xcode6默认不支持armv7s
  7. 表达式求值(河南省第四届ACM试题-C题)题解
  8. mysql 存储过程需要DELIMITER
  9. Forbidden You don&#39;t have permission to access / on this server.
  10. 程序猿媛 九:Adroid zxing 二维码3.1集成(源码无删减)
  11. bzoj2434阿狸的自动机
  12. mongodb3.6 副本集(三)mongodb 如何做数据备灾
  13. 别人的Linux私房菜(21)基础系统设置与备份策略
  14. 运维工具pssh和pdsh安装和使用
  15. JS对HTML字符的转义
  16. codeforces 804A Find Amir 思维/水题
  17. SQL查询今天、昨天、7天内、30天 - 转
  18. 解决提交按钮在IE浏览器正常在360浏览器不可用
  19. 输入操作遇到unknown error: cannot focus element
  20. CSS------如何让大小不一样的div中心对齐

热门文章

  1. java发送http请求get/post
  2. get 和 post 的区别
  3. CS内网横向移动 模拟渗透实操 超详细
  4. Linux—搭建Apache(httpd)服务
  5. 有趣的特性:CHECK约束
  6. AtCoder Educational DP Contest 总结
  7. 国产时序数据库IotDB安装、与SpringBoot集成
  8. 209. 长度最小的子数组--LeetCode
  9. Unhandled Exception: MissingPluginException(No implementation found for method launch on channel)
  10. 痞子衡嵌入式:浅析IAR下调试信息输出机制之硬件UART外设