[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]的更多相关文章
随机推荐
- Configuring VNC Server on Linux
linux安装oracle时,需用图形化界面安装.所以可采取下列的工具辅助安装 sysvinit (Original Method) systemd (New Method) VNC Clients ...
- 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。
在使用asp.net core的时候,采用take().skip()分页的时候报如下错误: SqlException: 'OFFSET' 附近有语法错误. 在 FETCH 语句中选项 NEXT 的用法 ...
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
参考页面:https://blog.csdn.net/idomyway/article/details/79572973 如果请求的是PHP页面: header("Access-Contro ...
- 常用sql语句总结(二)(更新数据,序列,创建数据表,约束,注释)
常用sql语句总结(二)(更新数据,序列,创建数据表,约束,注释) 一. 增 INSERT INTO 数据表(字段,字段,-) VALUES(值,值-); INSERT INTO emp(empno, ...
- 将markdown文档使用gulp转换为HTML【附带两套css样式】
将markdown文档使用gulp转换为HTML[附带两套css样式] 今天遇到一个需求,即将Markdown文档转为为HTML在网页展示,身为一名程序员,能用代码解决的问题,手动打一遍无疑是可耻的. ...
- python脚本练习之编译安装python
练习 py-shelll #coding=utf-8 import os,sys if os.getuid() == 0: pass else: print('当前用户不是root,请以root用户执 ...
- linux编译链接找不到库文件的解决方法。
今天编译出现ld: 0706-006 Cannot find or open library file: -l xerces-c_static,ld:open(): A file or directo ...
- 【FJOI 20170305】省选模拟赛
题面被改成了个猪... T1猪猪划船(boat) [题目描述] 6只可爱的猪猪们一起旅游,其中有3只大猪A,B,C,他们的孩子为3只小猪a,b,c.由于猪猪们十分凶残,如果小猪在没有父母监护的情况下, ...
- mc面试题记录
1.linux 查看磁盘空间 df -hl 2.根目录下有哪些文件及其作用 3.查找/tmp下的文件内容含有abc的命令 grep -rn "abc" /tmp4.linux下的s ...
- P2678 跳石头
传送门 思路: 二分跳跃的最短距离 mid .暴力判断如果有两个石头直接的距离小于 mid ,就把这个石头拿走.如果拿走的石头数目 cnt ≤ m,说明二分的答案可行,ans = mid,接着二分更短 ...