[NOIP2014D1]
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]的更多相关文章
随机推荐
- docker17.03.2安装
之前安装过docker 卸载 yum -y remove docker docker-common docker-selinux docker-engine docker-engine-selinux ...
- GOQTTemplate3的多线程化改造
GOQTTemplate3作为一个QT+OpenCV的平台,希望能够为使用者提供基础的跨平台的图像处理框架.图像处理算法和GUI两个线程的隔离,是必然需要的.在之前的版本中,都采用了OnTimer的方 ...
- bzoj 1283 序列 - 费用流
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求选出一些数使得原序列中每$m$个连续的数中不超过$K$个被选走.问最大的可能的和. 感觉建图好妙啊.. 考虑把问题转化成选$m$次数,每次 ...
- Selenium及Headless Chrome抓取动态HTML页面
一般的的静态HTML页面可以使用requests等库直接抓取,但还有一部分比较复杂的动态页面,这些页面的DOM是动态生成的,有些还需要用户与其点击互动,这些页面只能使用真实的浏览器引擎动态解析,Sel ...
- 单元测试系列之十一:Jmockit之mock特性详解
本文是Jmockit学习过程中,根据官网所列的工具特性进行解读. 1.调用次数约束(Invocation count constraints) 可以通过调用计数约束来指定预期和/或允许匹配给定期望的调 ...
- RESTClient的基本使用
1.本人使用的是火狐浏览器,其他浏览器应该也有(没试过),安装插件RESTClient. 2.1.打开RESTClient:
- [ZOJ 4016] Mergable Stack
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 直接用栈爆内存,看网上大神用数组实现的,构思巧妙,学习了! ...
- Cocos Creator学习二:查找节点和查找组件
1.目的:只有通过方便的获取节点对象以及组件,才能较好的进行逻辑控制. 2.通过 cc.find(节点全路径名称字符串) 获取节点. 3.通过getComponent获取组件(注意一个是类型,一个是类 ...
- Lab 11-2
Analyze the malware found in Lab11-02.dll. Assume that a suspicious file named Lab11-02.ini was also ...
- 20190412wdVBA 排版
Sub LayoutForExamPaper() Dim StartTime As Variant Dim UsedTime As Variant StartTime = VBA.Timer Appl ...