[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]的更多相关文章
随机推荐
- axure原型设计
在上一个学期的学习中,我们已经初步学习了axure的使用方法,它可以为负责定义需求设计,功能和界面的人员能快速设计出所需产品. 引入:在我们想为软件设计原型的时候,纸质原型很难表达交互的界面,与此同时 ...
- 为基于OpenCV的图像处理程序编写界面—关于QT\MFC\CSharp的选择以及GOCW的介绍
基于OpenCV编写图像处理项目,除了算法以外,比较重要一个问题就是界面设计问题.对于c++语系的程序员来说,一般来说有QT/MFC两种考虑.QT的确功能强大,特别是QML编写andr ...
- C# readonly与const区别
静态常量:是指编译器在编译时候会对常量进行解析,并将常量的值替换成初始化的那个值. 动态常量的值则是在运行的那一刻才获得的,编译器编译期间将其标示为只读常量,而不用常量的值代替,这样动态常量不必在声明 ...
- android源码编译出现No private recovery resources for TARGET_DEVICE解决方法
mmm或mm出现以下提示的解决方法:Terminal log:No private recovery resources for TARGET_DEVICE xxxxxxmake: Entering ...
- main函数的的两个参数
C语言中main函数的参数有两个,这两个参数写为argc和argv.因此,main函数的函数头可写为:main(argc,argv);C语言还规定argc(第一个形参)必须是整型变量,argv( 第二 ...
- 2018年—2019年第二学期第四周C#学习个人总结
第五章面向对象高级包括:5.1类的继承中有5.1.1继承的概念:一是在现实生活中,继承一般指的是子女继承父辈的财产;在C#,类的继承是指在一个现有类的基础上去构建一个新的类,构建出来的新类被称作子类, ...
- MAC终端神器iterm2——告别黑白
https://www.cnblogs.com/soyxiaobi/p/9695931.html
- elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异
目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...
- 关于C++中ios::sync_with_stdio(false)
粘贴自:https://blog.csdn.net/weixin_44015865/article/details/84974373 在C++中的输入和输出有两种方式,一种是scanf和printf, ...
- 配置IPMI
服务器电源管理 查看服务器电源状态 ipmitool chassis power status 关闭服务器电源 ipmitool chassis power off 打开服务器电源 ipmitool ...