gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017
西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg
A.水题,排序
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
#define lowbit(i) ((i)&(-i))
const ll maxv = 1e5 + ; ll n,d[maxv], c[maxv]; void update(ll x, ll v)
{
for (ll i = x; i < maxv; i+=lowbit(i))
{
c[i] += v;
}
} ll getsum(ll x)
{
ll sum = ;
for (ll i = x; i > ; i -= lowbit(i))
{
sum += c[i];
}
return sum;
} int main()
{
scanf("%lld", &n);
for (ll i = ; i <= n; i++)
{
scanf("%lld", &d[i]);
}
sort(d+ , d+ + n);
ll ans = ;
for (ll i = ; i <= n; i++)
{
ll num = getsum(i-);
num = (i - ) - num;
//printf("%lld %lld\n", i, num);
ans += num;
update(d[i], );
}
ans *= ;
printf("%lld\n", ans);
}
B.找到树的直径,倍增地跳跃计算答案
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<functional>
#include<vector>
using namespace std;
typedef long long LL; int n;
vector<int>e[];
bool vis[];
int Root, Tail; int BFS(int st)
{
for (int i = ; i <= n; i++)vis[i] = false;
queue<int>q;
q.push(st);
vis[st] = true;
int ret = st;
while (!q.empty())
{
int t = q.front(); q.pop();
ret = t;
for (int i = ; i < e[t].size(); i++)
{
int to = e[t][i];
if (!vis[to])
{
q.push(to);
vis[to] = true;
}
}
}
return ret;
} int len; void DFS(int nx, int pr, int st)
{
len = max(len, st);
for (int i = ; i < e[nx].size(); i++)
{
int to = e[nx][i];
if (to != pr)
{
DFS(to, nx, st + );
}
}
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n - ; i++)
{
int u, v;
scanf("%d %d", &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}
Root = BFS();
Tail = BFS(Root);
len = ;
DFS(Root, -, );
//printf("%d %d\n", Root, Tail);
int ans = ;
int tl = ;
while (tl<len-)
{
ans++;
tl <<= ;
}
printf("%d\n", ans); }
C.水题
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<map>
using namespace std; char s[];
int main()
{
scanf("%s", s);
int len = strlen(s);
int lsc = , pcms = ;
for (int i = ; i < len-; i++)
{
if (s[i] == 'L'&&s[i + ] == 'S'&&s[i + ] == 'C')lsc++;
}
for (int i = ; i < len - ; i++)
{
if (s[i] == 'P'&&s[i + ] == 'C'&&s[i + ] == 'M'&&s[i + ] == 'S')pcms++;
}
if (pcms > lsc)printf("PCMS\n");
else if (pcms < lsc)printf("LSC\n");
else printf("Tie\n"); }
D.比赛没来得及写的题。(1953.1.1居然是星期六!!一直以为是星期日!!!)
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
int days[] = { , , , , , , , , , , , , }; int q, st, ed, day, month, gi[], ans[]; bool isleap(int year)
{
return (year % == ) || ((year % == ) && (year % ));
} int cal(int yy, int mm, int dd)
{
int sum = ;
for (int i = ; i < mm; i++)
{
sum += days[i];
if (isleap(yy) && i == )
sum++;
}
return sum+dd-;
} void cycle(int mm,int dd)
{
int cnt=,now = ;//1953/1/1是星期六
for (int i = ; i <= + ; i++)
{
if (mm == && dd == && !isleap(i))
{
ans[cnt++] = ;
}
else
{
ans[cnt++] = (cal(i, mm, dd) + now - ) % + ;
}
if (isleap(i))
now = (now + - ) % + ;
else
now = (now + - ) % + ;
}
} int main()
{
scanf("%d", &q);
while (q--)
{
memset(ans, , sizeof(ans));
memset(gi, , sizeof(gi));
scanf("%d %d %d %d", &st, &ed, &month, &day);
cycle(month, day);
int numed = (ed- + ) / ;
int numst = (st - ) / ;
for (int i = ; i <= ; i++)
{
gi[ans[i]] += (numed - numst);
}
int mped = ed - + - numed * ;
int mpst = st - - numst * ;
for (int i = ; i <= mpst; i++)
{
gi[ans[i]]--;
}
for (int i = ; i <= mped; i++)
{
gi[ans[i]]++;
}
printf("%d", gi[]);
for (int i = ; i <= ; i++)
{
printf(" %d", gi[i]);
}
puts("");
}
return ;
}
E.还没看,待补
F.还没写,待补
G.还没写,待补
H.几何板子题,两圆交点,我抄错板子错了好久quq
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const double eps = 1e-; struct Point
{
double x, y;
Point(double _a, double _b) :x(_a), y(_b) {}
Point() {}
}; Point intersection(const Point &u1, const Point &u2, const Point &v1, const Point &v2)
{
Point res = u1;
double t = ((u1.x - v1.x)*(v1.y - v2.y) - (u1.y - v1.y)*(v1.x - v2.x)) / ((u1.x - u2.x)*(v1.y - v2.y) - (u1.y - u2.y)*(v1.x - v2.x));
res.x += (u2.x - u1.x)*t;
res.y += (u2.y - u1.y)*t;
return res;
} double dis(const Point &p1, const Point &p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
} void play(const Point &c, double r, const Point &l1, const Point &l2, Point &p1, Point &p2)
{
Point p = c;
p.x += l1.y - l2.y;
p.y += l2.x - l1.x;
p = intersection(p, c, l1, l2);
double t = sqrt(r*r - dis(p, c)*dis(p, c)) / dis(l1, l2);
p1.x = p.x + (l2.x - l1.x)*t;
p1.y = p.y + (l2.y - l1.y)*t;
p2.x = p.x - (l2.x - l1.x)*t;
p2.y = p.y - (l2.y - l1.y)*t;
} void play2(const Point &c1, double r1, const Point &c2, double r2, Point &p1, Point &p2)
{
Point u, v;
double t = ( + (r1*r1 - r2*r2) / dis(c1, c2) / dis(c1, c2)) / ;
u.x = c1.x + (c2.x - c1.x)*t;
u.y = c1.y + (c2.y - c1.y)*t;
v.x = u.x + c1.y - c2.y;
v.y = u.y - c1.x + c2.x;
play(c1, r1, u, v, p1, p2);
} double x1, x2, r1, yy, y2, r2; int main()
{
cin >> x1 >> yy >> r1;
cin >> x2 >> y2 >> r2;
Point ans1, ans2;
if (r1 > r2) {
swap(x1, x2);
swap(yy, y2);
swap(r1, r2);
}
double ds = dis(Point(x1, yy), Point(x2, y2));
if (r2 >= ds)
{
printf("%.6lf %.6lf\n", x1, yy);
return ;
}
play2(Point(x1, yy), r1, Point(x2, y2), r2, ans1, ans2);
printf("%.6lf %.6lf\n", ans1.x, ans1.y);
return ;
}
I.瞎搞
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
const double eps = 1e-;
ll ax[];
int main(void) {
ll n;
scanf("%lld", &n);
for (int i = ; i < n; i++) {
scanf("%lld", &ax[i]);
}
if (n == ) {
printf("0\n");
return ;
}
else if (n == ) {
printf("%lld\n", min(abs(ax[] - ax[]),abs(ax[]+ax[])));
return ;
}
vector<ll>v;
ll sum = ;
for (int i = ; i<n - ; i++) {
sum += abs(ax[i + ] - ax[i]);
v.push_back(abs(ax[i + ] + ax[i]) - abs(ax[i + ] - ax[i]));
}
sort(v.begin(), v.end());
if (v[] < ) {
sum += v[];
}
if (v[] < ) {
sum += v[];
}
printf("%lld\n", sum);
}
J.还没写,待补
K.水题,四个角满足即可
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<functional>
#include<vector>
using namespace std;
typedef long long LL; int n; int main()
{
int n, m, k;
int cnt = ;
scanf("%d %d %d", &n, &m, &k);
for (int i = ; i <= k; i++)
{
int x, y;
scanf("%d %d", &x, &y);
if (x == && y == m)
cnt++;
else if (x == && y == )
cnt++;
else if (x == n&&y == )
cnt++;
else if (x == n&&y == m)
cnt++;
}
int tmp = ;
if (n == && m == )
tmp = ;
else if (n == || m == )
tmp = ;
printf("%d\n", tmp - cnt);
return ;
}
L.还没写,待补
gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017的更多相关文章
- Codeforces Gym101522 C.Cheering-字符串 (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
C.Cheering To boost contestants' performances in the 20th La Salle - Pui Ching Programming Challenge ...
- Codeforces Gym101522 D.Distribution of Days-算日期 (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
D.Distribution of Days The Gregorian calendar is internationally the most widely used civil calendar ...
- Codeforces Gym101522 A. Ambiguous Dates (La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017)
A. Ambiguous Dates There are two popular formats for representing a date: day/month/year or month/da ...
- gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest
Kuma Rider久违的第二场训练,这场很水,又在vj的榜单上看到第一场的大哥了,2小时ak,大哥牛啤! A.水 #include<cstdio> #include<iostrea ...
- 动词的时态(Les temps du verbe )
在开始讲解直陈式现在时的主要用法之前,我们有必要先搞清楚两个基本概念:▶语式(mode):语式是动词表达动作的方式.一个动作,可以作为实在的事表达出来,也可以作为希望或单纯设想的事表达出来,法语动词共 ...
- 每周一书-《鸟哥的Linux私房菜》获奖公布
<鸟哥的Linux私房菜>一书的赠书活动时间为2016年10月19日到10月31日, 也就是今天结束. 首先要感谢QQ号为:1084830483(路在远方),来自哈尔滨工程大学的同学赠送给 ...
- 2017年USNews美国大学研究生专业排名
2017年USNEWS美国大学研究生专业排名最佳商学院排名 排名 学校 费用 注册人数 #1 Harvard University Boston, MA $61,225 per year (full- ...
- CVPR 2017 Paper list
CVPR2017 paper list Machine Learning 1 Spotlight 1-1A Exclusivity-Consistency Regularized Multi-View ...
- 数据库 之MySQL 简单教程
So Easy系列之MySQL数据库教程 1. 数据库概述 1.1. 数据库概述 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和 ...
随机推荐
- 解决iPhone滑动时滑到另一个层级导致卡顿问题
问题概览: 两个div都可以滑动时,会造成滑动顶层div时,底层div也会跟着滑动.如图示. 解决方法: 添加CSS即可. 代码如下 * { -webkit-overflow-scrolling: t ...
- Spark 分布式调试工具
0. 说明 编写工具类,考察 Spark 分布式程序的执行地点 1. 工具类编写 [ JMX ] Java Management Extend , Java 管理扩展服务. 主要用于运维和监控. [测 ...
- ZooKeeper 分布式协调服务介绍
0. 说明 从自己的独立博客迁移,该部分为 Zookeeper分布式协调服务介绍 原文链接 ZooKeeper 指南 1. ZooKeeper 简介 [官方介绍] ZooKeeper 是一种集中式服 ...
- 【转】MySQL双主一致性架构优化
[原文]https://www.toutiao.com/i6594414914838725133/ 一.双主保证高可用 MySQL数据库集群常使用一主多从,主从同步,读写分离的方式来扩充数据库的读性能 ...
- [MySQL]在安装windows版MySQL时遇到过如下问题Error Nr.1045和Error.Nr.2003,相应解决办法如下
1.准备mysql server-5.0.27.exe 2.按照指导安装,在安装到最后一步时遇到如下两个错误: 2.1.出现错误Error Nr.1045 解决办法: a).停止MySQL服务:我的电 ...
- ip 报文头
- python第三十课--异常(finally讲解)
演示:finally语句的作用 try: fr="" path=r'kaifanglist1.txt' fr=open(path,encoding='utf-8') print(f ...
- POJ 1066 昂贵的聘礼
Description 年轻的探险家来到了一个印第安部落里. 在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长减 ...
- Redis系列二:reids介绍
一.什么是redis.redis有哪些特性.redis有哪些应用场景.redis的版本 1. 什么是redis redis是一种基于键值对(key-value)数据库,其中value可以为string ...
- Netty入门(十)解码分隔符和基于长度的协议
我们需要区分不同帧的首尾,通常需要在结尾设定特定分隔符或者在首部添加长度字段,分别称为分隔符协议和基于长度的协议,本节讲解 Netty 如何解码这些协议. 一.分隔符协议 Netty 附带的解码器可以 ...