T1

Problem

洛谷

Solution

一道非常裸的模拟题。直接枚举每次猜拳就可以了。

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int x[205], y[205];
ll read()
{
ll ans = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
return ans * zf;
}
int check(int X, int Y)
{
if (X == Y) return 0;
if (X == 0)
if (Y == 2 || Y == 3) return 1;
else return -1;
if (X == 1)
if (Y == 0 || Y == 3) return 1;
else return -1;
if (X == 2)
if (Y == 1 || Y == 4) return 1;
else return -1;
if (X == 3)
if (Y == 2 || Y == 4) return 1;
else return -1;
if (X == 4)
if (Y == 0 || Y == 1) return 1;
else return -1;
}
int main()
{
int n = read(), XX = read(), YY = read();
for (int i = 0; i < XX; i++) x[i] = read();
for (int i = 0; i < YY; i++) y[i] = read();
int ansx = 0, ansy = 0;
for (int time = 0; time < n; time++)
{
int X = x[time % XX], Y = y[time %YY];
if (check(X, Y) == 1) ansx++;
else if (check(X, Y) == -1) ansy++;
}
printf("%d %d\n", ansx, ansy);
}

T2

Problem

洛谷

Solution

这题其实只要枚举每个点,选它的两条边构成一对,记录max和sum。

求sum注意一下用前缀和优化就好了,求max只需算每个点连着的点中最大的两个点相乘的最大值。

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll read()
{
ll ans = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
return ans * zf;
}
int vet[400005], head[200005], nextx[400005];
ll w[200005], num = 0;
const ll mo = 10007;
void add(int u, int v)
{
vet[++num] = v;
nextx[num] = head[u];
head[u] = num;
}
int main()
{
int n = read();
for (int i = 1; i < n; i++)
{
int u = read(), v = read();
add(u, v);
add(v, u);
}
for (int i = 1; i <= n; i++) w[i] = read();
ll ans = 0, maxX = 0;
for (int u = 1; u <= n; u++)
{
ll First = 0, Second = 0, sum = 0;
for (int i = head[u]; i; i = nextx[i])
{
int v = vet[i];
if (w[v] > First)
{
Second = First;
First = w[v];
}
else if (w[v] > Second) Second = w[v];
ans = (ans + 2 * sum * w[v]) % mo;
maxX = max(maxX, First * Second);
sum += w[v];
}
}
printf("%lld %lld\n", maxX, ans);
}

[NOIP2014D1]的更多相关文章

随机推荐

  1. layui table数据表格reload where参数保留问题

    layui table数据表格reload where参数保留问题 在使用layui过程中多多少少会遇到些问题 table reload 有个坑:reload时where参数会保留上次的参数,如果用 ...

  2. Hadoop-Impala学习笔记之入门

    CDH quickstart vm包含了单节点的全套hadoop服务生态,可从https://www.cloudera.com/downloads/quickstart_vms/5-13.html下载 ...

  3. Servlet3.0与springmvc那些事

    官方文档:https://docs.spring.io/spring/docs/5.0.2.RELEASE/spring-framework-reference/web.html#mvc-servle ...

  4. day 05

    今天学习了数据类型的操作 首先需要知道 数据类型有哪些 1.数字类型 2.字符串类型 3.布尔类型 4.列表类型 5.字典类型 6.元组类型 7.集合类型类型 1.1数字类型里面有分 为整型(int) ...

  5. word模板导出的几种方式:第一种:占位符替换模板导出(只适用于word中含有表格形式的)

    1.占位符替换模板导出(只适用于word中含有表格形式的): /// <summary> /// 使用替换模板进行到处word文件 /// </summary> public ...

  6. nginx 配置反向代理

    之前的前端是8123端口,使用此端口让nginx的反向代理. vim /etc/nginx/conf.d/80-fr.conf upstream cats{ server 127.0.0.1:8123 ...

  7. re模块的应用

    import re # 正则表达式中的转义 : # '\(' 表示匹配小括号 # [()+*?/$.] 在字符组中一些特殊的字符会现出原形 # 所有的 \w \d \s(\n,\t, ) \W \D ...

  8. 【做题】ZJOI2017仙人掌——组合计数

    原文链接 https://www.cnblogs.com/cly-none/p/ZJOI2017cactus.html 给出一个\(n\)个点\(m\)条边的无向连通图,求有多少种加边方案,使得加完后 ...

  9. python from entry to abandon4

    python from entry to abandon系列的收官之作    本篇博客将会介绍<简明Python教程>的最后四章内容.并在最后附上对于本书的个人评价和下阶段自学Python ...

  10. Python连接MySQL数据库之pymysql模块

    pymysql 在python3.x 中用于连接MySQL服务器的一个库:Python2中则使用mysqldb pymysql的模块的基本的使用 # 导入pymysql模块 import pymysq ...