2018 icpc 沈阳
https://codeforces.com/gym/101955
J
签到
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
using namespace std;
const int maxn = 5e5+;
ll read() {
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= '')) {
if (ch == '-')f = -;
ch = getchar();
};
while (ch >= '' && ch <= '') {
x = x * + (ch - '');
ch = getchar();
};
return x*f;
}
char s[];
int main(){
int T;
cin>>T;
int n;
ll ans,a,b;
int Case = ;
while(T--){
n=read();
ans = ;
fo(tt,,n) {
cin.getline(s + , );
b = a = ;
if (s[] == 'b') a = ;
if (s[] == 'c') a = ;
if (s[] == 'i') a = ;
if (s[] == 'l' && s[] == 'l')a = ;
if (s[] == '_')a = ;
if (s[] == 'f')a = ;
if (s[] == 'd')a = ;
if (!a)a = ;
int len = strlen(s + );
int bs = ;
if (s[len - ] == ']') {
for (int i = len - ; i >= ; i--) {
if (s[i] == '[')break;
b = b + (s[i] - '') * bs;
bs *= ;
}
} else {
b = ;
}
ans += a * b;
}
if(ans%) ans = ans/ + ;
else ans = ans/;
cout<<"Case #"<<++Case<<": "<<ans<<endl;
}
return ;
}
C
先乘一个k!,并假定前k个数是有序的
最长上升序列长度是n-1,就要把一个数字排除在外,就要把一个数字插入到其他位置
分成三种情况:前k个数里的某个数插入到后n-k个里,后n-k个数插入到前k个数里,后n-k个数插入到后n-k个数里。
分别统计,要注意相邻两个数交换的情况,只能被统计一次。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
using namespace std;
const int maxn = ;
ll read() {
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= '')) {
if (ch == '-')f = -;
ch = getchar();
};
while (ch >= '' && ch <= '') {
x = x * + (ch - '');
ch = getchar();
};
return x*f;
}
int main(){
int T;
T=read();
ll n,k,mod;
ll ans,a,b;
int Case = ;
while(T--){
n=read();
k=read();
mod=read();
k = min(n,k);
a=;
for(ll i = ;i <= k;i++){
a*=i;
a%=mod;
}
b=(n-)*(n-k)+;
b%=mod;
ans = (a*b)%mod;
cout<<"Case #"<<++Case<<": "<<ans<<endl;
}
return ;
}
G
圆上的整数点数量是相当有限的,对于这个题来说,询问的半径是固定不变的,可以预处理圆上的整点,由于点的数量很小,接下来就暴力修改查询即可。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
using namespace std;
const int maxn = ,maxk=1e7+;
ll read() {
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= '')) {
if (ch == '-')f = -;
ch = getchar();
};
while (ch >= '' && ch <= '') {
x = x * + (ch - '');
ch = getchar();
};
return x*f;
}
const int fx[] = {-,,-,};
const int fy[] = {-,-,,};
vector<int> st[maxk],st2[maxk];
int n,m,flag;
ll weight[maxn+][maxn+];
int flags[maxn+][maxn+];
bool judge(int y,int x){
return y>=&&y<=maxn&&x>=&&x<=maxn;
}
void add(int y,int x,ll w){
weight[y][x] = w;
flags[y][x] = flag;
}
void del(int y,int x){
weight[y][x] = ;
flags[y][x]--;
}
void inc(int y,int x,ll k,ll w){
int sz = st[k].size();
int dy,dx,nowy,nowx;
fo(i,,sz-){
dx = st[k][i];
dy = st2[k][i];
fo(j,,){
if(dx==&&(j==||j==))continue;
if(dy==&&(j==||j==))continue;
nowy = y + dy*fy[j];
nowx = x + dx*fx[j];
if(!judge(nowy,nowx))continue;
if(flags[nowy][nowx]==flag) weight[nowy][nowx] += w;
} }
}
ll query(int y,int x,ll k){
int sz = st[k].size();
int dy,dx,nowy,nowx;
ll ans = ;
fo(i,,sz-){
dx = st[k][i];
dy = st2[k][i];
fo(j,,){
if(dx==&&(j==||j==))continue;
if(dy==&&(j==||j==))continue;
nowy = y + dy*fy[j];
nowx = x + dx*fx[j];
if(judge(nowy,nowx)){
if(flags[nowy][nowx]==flag)ans += weight[nowy][nowx];
}
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
int T,Case=;
T=read();
ll lastans = ;
fo(i, , ) {
fo(j, , ) {
if (i * i + j * j > 1e7) break;
st[i * i + j * j].push_back(i);
st2[i * i + j * j].push_back(j);
}
}
while(T--) {
flag++;
lastans=;
int y, x, cmd;
ll k, w;
cout<<"Case #"<<++Case<<":"<<endl;
n = read();
m = read();
fo(i, , n) {
y = read();
x = read();
w = read();
add(y, x, w);
}
fo(i, , m) {
cmd = read();
y = read();
x = read();
y = (y + lastans) % 6000ll + 1ll;
x = (x + lastans) % 6000ll + 1ll;
if (cmd == ) {
w = read();
add(y, x, w);
} else if (cmd == ) {
del(y, x);
} else if (cmd == ) {
k = read();
w = read();
inc(y, x, k, w);
} else {
k = read();
cout << (lastans = query(y, x, k)) << endl;
}
}
}
return ;
}
K
首先考虑一般意义上的约瑟夫环问题,把k-1个人删去后,将k...n,0..k-2重新编号,就变成一个规模为n-1的一模一样的问题了。
考虑这个题,这次求的不是最后一个,而是第m个人把k-1删去之后,就变成了从n-1个人里找第m-1个人了。
直接递推需要一个o(m)的循环,但是题目范围说m和k总有一个很小,当k很小m很大时,我们可以让它直接顶到头而不是一项一项递推,加速递推过程。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld long double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 3e-11
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
ll n, m, k;
int main()
{
int T;
T = read();
int tt = ;
while (T--)
{
tt++;
n = read();
m = read();
k = read();
ll ans = (k - ) % (n - m + );
if (k == )
{
ans = m - ;
}
else
{
fo(i, n - m + , n)
{
ans = (ans + k) % i;
ll js = i - ans - ;
js /= k;
js--;
if (n - i - < js)
js = n - i - ;
if (js > )
{
i += js;
ans = ans + k * js;
}
}
}
printf("Case #%d: %I64d\n", tt, ans + );
}
return ;
}
L
计算几何。
首先将外部圆与中心圆的交点求出,先看能不能取到直径,可以取到的充要条件是,存在一个交点,它的对称点没有被外部圆切去。
若不能取到直径,所有交点两两连线,去距离的最大值。
本地精度存在一些问题,long double会导致WA,只有double可以过,具体原因待探究。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-10
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
struct dat
{
ld v;
bool isr;
int p;
friend bool operator<(dat a, dat b)
{
return a.v < b.v;
}
};
int cnt;
ll n;
ld R;
ld px[maxn], py[maxn], pr[maxn], ans;
ld fpx[maxn], fpy[maxn];
dat ang[maxn * ];
dat fang[maxn * ];
ld getang(ld a, ld b, ld c)
{
return acos((a * a + b * b - c * c) / (a * b + a * b));
}
ld tryang(ld agl)
{
if (agl < )
agl = -agl;
return R * sin(agl / 2.0) * 2.0;
}
int main()
{
int T;
T = read();
int tt = ;
while (T--)
{
tt++;
cnt = ;
n = read();
R = read();
ld dis, baseAngle;
fo(i, , n)
{
px[i] = read();
py[i] = read();
pr[i] = read();
dis = sqrt(px[i] * px[i] + py[i] * py[i]);
baseAngle = atan2(py[i], px[i]);
if (pr[i] + R < dis)
{
continue;
}
if (fabs(R - pr[i]) > dis)
{
continue;
} ang[cnt + ].v = baseAngle - getang(dis, R, pr[i]);
ang[cnt + ].v = baseAngle + getang(dis, R, pr[i]);
if (ang[cnt + ].v < )
ang[cnt + ].v += pi + pi;
if (ang[cnt + ].v >= pi + pi)
ang[cnt + ].v -= pi + pi;
if (ang[cnt + ].v < )
ang[cnt + ].v += pi + pi;
if (ang[cnt + ].v >= pi + pi)
ang[cnt + ].v -= pi + pi;
cnt += ;
}
if (cnt == )
ans = R + R;
fo(i, , cnt)
{
fpx[i] = -R * cos(ang[i].v);
fpy[i] = -R * sin(ang[i].v);
}
ans = 0.0;
fo(i, , cnt)
{
fo(j, i + , cnt)
{
ans = max(ans, tryang(ang[i].v - ang[j].v));
}
}
ld tx, ty;
fo(i, , cnt)
{
bool ok = false;
fo(j, , n)
{
if ((fpx[i] - px[j]) * (fpx[i] - px[j]) + (fpy[i] - py[j]) * (fpy[i] - py[j]) < pr[j] * pr[j])
{
ok = true;
break;
}
}
if (!ok)
{
ans = R + R;
break;
}
}
printf("Case #%d: %.15lf\n", tt, ans);
}
return ;
}
2018 icpc 沈阳的更多相关文章
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)
[传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...
- 2018 ICPC 沈阳网络预赛 Fantastic Graph (优先队列)
[传送门]https://nanti.jisuanke.com/t/31447 [题目大意]:有一个二分图,问能不能找到它的一个子图,使得这个子图中所有点的度数在区间[L,R]之内. [题解]首先我们 ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)
题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...
- 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解
题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...
- 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)
Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...
- 2017 icpc 沈阳网络赛
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
随机推荐
- splice方法
此方法有三种用法: 第一种: 删除功能 返回删除内容 索引从0开始 var arr = [1,2,3,4]; var arr2 = arr.splice(0,2); arr2 ===> [1, ...
- Spring Boot整合Spring Security总结
一.创建Spring Boot项目 引入Thymeleaf和Web模块以及Spring Security模块方便进行测试,先在pom文件中将 spring-boot-starter-security ...
- apache traffic server安装
wget http://mirrors.hust.edu.cn/apache/trafficserver/trafficserver-7.1.1.tar.bz2 tar -jxvf trafficse ...
- gcc编译动态链接库
以下是windows环境下用gcc编译动态链接库的尝试过程. 环境准备 编译使用的MinGW,64位的官网可以找到下载地址. 项目建立及代码编写 在任意地方新建一个目录,保存这个项目,然后新建一个c源 ...
- caffe py3 docker
https://hub.docker.com/r/mapler/caffe-py3/ docker pull mapler/caffe-py3 docker run -it mapler/caff ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(3)|所有权Ownership]
今天我们来讲讲rust最难,也是最重要的概念: Ownership,Borrowing,Lifetimes 首先我们来看看:ownership(所有权) 我们来看看下面的代码: let a = [1, ...
- 【JAVA】Maven profiles控制多环境数据源日志打包(转载)
https://blog.csdn.net/qq_17213067/article/details/81661295
- DevExpress WPF v19.1新版亮点:Scheduler等控件新功能
行业领先的.NET界面控件DevExpress 日前正式发布v19.1版本,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WPF v19.1中新增的一些控件及部 ...
- mysql的视图、索引、触发器、存储过程
USE school; SELECT * FROM sc; SELECT * FROM course; SELECT * FROM student; SELECT * FROM teacher; -- ...
- Jenkins打包Maven项目
Jenkins是一个用于持续集成的服务,简单些说,就是提交代码后,点一下(也可以设置自动检测),系统会自动下载你的代码并编译,然后复制或上传到指定位置,并给所有相关人发送邮件. 一.环境搭建 1.下载 ...