2019 ccpc 秦皇岛
D
如果1/n是有限小数,不停乘以10,一定在有限次之后成为一个整数。
10的质因子只有2和5,只要保证分母的质因子只有2和5即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#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 ll long long
#define ld double
using namespace std;
const int maxn = ;
const ll mod = 1e9 + ;
const double eps = 1e-;
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,n;
T=read();
while(T--){
n=read();
while(n%==)n/=;
while(n%==)n/=;
if(n>){
printf("Yes\n");
}else{
printf("No\n");
}
}
return ;
}
F
仙人掌,环之间不相互影响,一个环至少删掉一条边,链无所谓,分别计算乘法原理合并
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#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 ll long long
#define ld double
using namespace std;
const int maxn = ;
const ll mod = ;
const double eps = 1e-;
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;
}
vector<int> g[maxn];
int n,m;
int d[maxn],rem;
ll ans,pw[maxn*];
void dfs(int u,int fa,int deep){
d[u] = deep;
int v,sz=(int)g[u].size()-;
fo(i,,sz){
v=g[u][i];
if(v==fa)continue;
if(!d[v]) dfs(v,u,deep+);
else if(d[v]<d[u]){
ans=(ans*(pw[d[u]-d[v]+]-+mod))%mod;
rem -= (d[u]-d[v]+);
}
}
}
int main()
{
pw[]=;pw[]=;
fo(i,,) pw[i] = (pw[i-]+pw[i-])%mod;
int u,v;
while(scanf("%d%d",&n,&m)!=EOF){
ans=;
rem=m;
fo(i,,n){
d[i]=;
g[i].clear();
}
fo(i,,m){
u=read();v=read();
g[u].push_back(v);
g[v].push_back(u);
}
fo(i,,n){
if(!d[i]){
dfs(i,,);
}
}
ans=(ans*pw[rem])%mod;
printf("%lld\n",ans);
}
return ;
}
I
和之前做过的一个题很像,但是那个题需要贪心的性质为支撑,这个dp直接做就行了
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#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 ll long long
#define ld double
using namespace std;
const int maxn = ;
const ll mod = ;
const double eps = 1e-;
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 n;
int req[][];
char s[][]={"QQQ","QQW","QQE","WWW","QWW","WWE","EEE","QEE","WEE","QWE"};
char t[] = "YVGCXZTFDB";
char a[maxn],b[maxn];
int dp[maxn][][][],sum1[maxn][][],sum2[maxn][],sum3[maxn],cnt[];
int main()
{
fo(i,,){
fo(j,,){
if(s[i][j]=='Q')req[t[i]][]++;
if(s[i][j]=='W')req[t[i]][]++;
if(s[i][j]=='E')req[t[i]][]++;
}
}
while(scanf("%s",a+)!=EOF){
n=strlen(a+);
int m = ;
fo(i,,n){
if(a[i] != a[i-]) b[++m] = a[i];
}
swap(n,m);
memset(dp,0x3f,sizeof(dp));
memset(sum1,,sizeof(sum1));
memset(sum2,,sizeof(sum2));
memset(sum3,,sizeof(sum3));
int ans = mod;
fo(i,,n){
fo(t1,,){
fo(t2,,){
fo(t3,,){
cnt[]=cnt[]=cnt[]=;
cnt[t1]++;
cnt[t2]++;
cnt[t3]++;
if(cnt[]!=req[b[i]][]||cnt[]!=req[b[i]][]||cnt[]!=req[b[i]][])continue; dp[i][t1][t2][t3] = sum3[i-]+;
if(sum1[i-][t1][t2]) dp[i][t1][t2][t3] = min(dp[i][t1][t2][t3],sum1[i-][t1][t2]+);
if(sum2[i-][t1]) dp[i][t1][t2][t3] = min(dp[i][t1][t2][t3],sum2[i-][t1]+);
if(!sum1[i][t2][t3] || (sum1[i][t2][t3] > dp[i][t1][t2][t3])){
sum1[i][t2][t3] = dp[i][t1][t2][t3];
}
if(!sum2[i][t3] || (sum2[i][t3] > dp[i][t1][t2][t3])){
sum2[i][t3] = dp[i][t1][t2][t3];
}
if(!sum3[i] || (sum3[i] > dp[i][t1][t2][t3])){
sum3[i] = dp[i][t1][t2][t3];
}
if(i==n) ans=min(ans,dp[i][t1][t2][t3] + m);
}
}
}
}
printf("%d\n",ans);
}
return ;
}
J
倒过来做kmp找循环节
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#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 ll long long
#define ld double
using namespace std;
const int maxn = ;
const ll mod = ;
const double eps = 1e-;
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 nxt[maxn];
void kmp_pre(char x[], int m, int next[])
{
int i, j;
j = next[] =-;
i = ;
while (i < m)
{
while (- != j && x[i] != x[j])
j = next[j];
next[++i] = ++j;
}
}
ll a, b,ans;
char s[maxn], x[maxn];
int n, m;
int main()
{
while (scanf("%lld%lld", &a, &b) != EOF)
{
scanf("%s", s + );
n = strlen(s + );
m = ;
fd(i, , n)
{
if (s[i] < '' || s[i] > '')
break;
x[++m] = s[i];
}
kmp_pre(x+,m,nxt);
ans = a-b;
fo(i,,m){
ans=max(ans,a*i-b*(i-nxt[i]));
}
printf("%lld\n",ans);
} return ;
}
A
直角三角形,就要看直角边在哪个点上,分两种情况讨论,然后围绕着直角点极角排序,找垂直的边。
#pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <ctime>
#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 (int i = l; i <= r; i++)
#define fd(i, l, r) for (int i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-7
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 Point
{
ll x, y;
int isq,id;
Point() {}
Point(ll _x, ll _y)
{
x = _x;
y = _y;
}
ll operator^(const Point &b) const
{
return x * b.y - y * b.x;
}
ll operator*(const Point &b) const
{
return x * b.x + y * b.y;
}
Point operator-(const Point &b) const
{
return Point(x - b.x, y - b.y);
}
Point operator+(const Point &b) const
{
return Point(x + b.x, y + b.y);
}
Point rotleft(){
return Point(-y,x);
}
Point rotright(){
return Point(y,-x);
}
int getfield(){
if(x>&&y>=)return ;
if(x<=&&y>)return ;
if(x<&&y<=)return ;
if(x>=&&y<)return ;
return ;
}
} ns[maxn], tmp[maxn],qs[maxn], now;
struct cmp
{
Point p;
cmp(const Point &p0){p = p0;}
bool operator()(const Point &aa,const Point &bb)
{
Point a = aa-p,b = bb-p;
if(a.getfield() != b.getfield()){
return a.getfield() < b.getfield();
}else{
return (a^b)>;
}
}
};
int n, q;
ll ans[maxn];
ll sum[maxn];
int main()
{
while (scanf("%d%d", &n, &q) != EOF)
{
mem(ans);
fo(i, , n)
{
scanf("%lld%lld",&ns[i].x,&ns[i].y);
ns[i].isq=;ns[i].id=i;
tmp[i]=ns[i];
}
fo(i, , q)
{
scanf("%lld%lld",&qs[i].x,&qs[i].y);
qs[i].isq=;qs[i].id=i;
now = qs[i];
sort(ns + , ns + + n, cmp(now));
fo(j,,n){
now=(ns[j]-qs[i]).rotleft();
now=qs[i]+now;
int ret = upper_bound(ns+,ns++n,now,cmp(qs[i])) - lower_bound(ns+,ns++n,now,cmp(qs[i]));
ans[i] += ret;
}
}
fo(i,,q){
ns[n+i]=qs[i];
}
fo(i,,n){
now = tmp[i];
sort(ns+,ns++n+q,cmp(tmp[i]));
fo(j,,n+q){
if(!ns[j].isq&&ns[j].id!=now.id)sum[j]=sum[j-]+;
else sum[j]=sum[j-];
}
fo(j,,n+q){
if(!ns[j].isq)continue;
now=(ns[j]-tmp[i]).rotleft();
now=tmp[i]+now;
ans[ns[j].id] += sum[upper_bound(ns+,ns++n+q,now,cmp(tmp[i]))-ns-] - sum[lower_bound(ns+,ns++n+q,now,cmp(tmp[i]))-ns-];
now=(ns[j]-tmp[i]).rotright();
now=tmp[i]+now;
ans[ns[j].id] += sum[upper_bound(ns+,ns++n+q,now,cmp(tmp[i]))-ns-] - sum[lower_bound(ns+,ns++n+q,now,cmp(tmp[i]))-ns-];
}
}
fo(i,,q) printf("%lld\n",ans[i]);
}
return ;
}
E
给某些节点一个通过量的限制,从某些点出发、一些终点,可以向网络流的方向考虑,如何建图?
分析性质,假如说一个机器人从格点的一个边进入,再从某个边出,如果有人跟他反着来,则必然会逆着他走的路到第一行。
如果有人顺着它的路线走,那么会跟他走进同一个终点。
也就是说,如果这个节点,它拐弯了,那就只能一个机器人走一次。
如果它没拐弯,横着走过去之后,竖着走过去不会和原来横着走的路径有同样或者相反的结果,也就是能走两次。
拆点,把每个点拆成横竖两个点,相邻的恒竖相连,可以走2次,同一个点横竖相连,割这个边就说明在这个点放了转向器,只能走一次。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define fd(i, l, r) for (int i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define ll long long
using namespace std;
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 MAXN = ; //点数的最大值
const int MAXM = ; //边数的最大值
const int INF = 0x3f3f3f3f;
struct Edge
{
int to, next, cap, flow;
} edge[MAXM]; //注意是 MAXM
int tol;
int head[MAXN];
int gap[MAXN], dep[MAXN], cur[MAXN];
void init()
{
tol = ;
memset(head,-, sizeof(head));
}
void addedge(int u, int v, int w, int rw = )
{
edge[tol].to = v;
edge[tol].cap = w;
edge[tol].flow = ;
edge[tol].next = head[u];
head[u] = tol++;
edge[tol].to = u;
edge[tol].cap = rw;
edge[tol].flow = ;
edge[tol].next = head[v];
head[v] = tol++;
}
int Q[MAXN];
void BFS(int start, int end)
{
memset(dep,-, sizeof(dep));
memset(gap, , sizeof(gap));
gap[] = ;
int front = , rear = ;
dep[end] = ;
Q[rear++] = end;
while (front != rear)
{
int u = Q[front++];
for (int i = head[u]; i != -; i = edge[i].next)
{
int v = edge[i].to;
if (dep[v] != -)
continue;
Q[rear++] = v;
dep[v] = dep[u] + ;
gap[dep[v]]++;
}
}
}
int S[MAXN];
int sap(int start, int end, int N)
{
BFS(start, end);
memcpy(cur, head, sizeof(head));
int top = ;
int u = start;
int ans = ;
while (dep[start] < N)
{
if (u == end)
{
int Min = INF;
int inser;
for (int i = ; i < top; i++)
if (Min > edge[S[i]].cap - edge[S[i]].flow)
{
Min = edge[S[i]].cap - edge[S[i]].flow;
inser = i;
}
for (int i = ; i < top; i++)
{
edge[S[i]].flow += Min;
edge[S[i] ^ ].flow -= Min;
}
ans += Min;
top = inser;
u = edge[S[top] ^ ].to;
continue;
}
bool flag = false;
int v;
for (int i = cur[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if (edge[i].cap - edge[i].flow && dep[v] + == dep[u])
{
flag = true;
cur[u] = i;
break;
}
}
if (flag)
{
S[top++] = cur[u];
u = v;
continue;
}
int Min = N;
for (int i = head[u]; i != -; i = edge[i].next)
if (edge[i].cap - edge[i].flow && dep[edge[i].to] < Min)
{
Min = dep[edge[i].to];
cur[u] = i;
}
gap[dep[u]]--;
if (!gap[dep[u]])
return ans;
dep[u] = Min + ;
gap[dep[u]]++;
if (u != start)
u = edge[S[--top] ^ ].to;
}
return ans;
}
int n,m,a,b;
char mp[][];
inline int tran(int y,int x,int dir){
int t = (y-)*m+x;
if(dir) t+=n*m;
return t;
}
inline bool jud(int y,int x){
return y>=&&y<=n&&x>=&&x<=m&&mp[y][x]=='';
}
int main()
{
int T=read();
while(T--){
init();
n=read();m=read();a=read();b=read();
fo(i,,n){
scanf("%s",mp[i]+);
}
fo(i,,n){
fo(j,,m){
if(!jud(i,j))continue;
if(jud(i-,j)) addedge(tran(i,j,),tran(i-,j,),);
if(jud(i+,j)) addedge(tran(i,j,),tran(i+,j,),);
if(jud(i,j-)) addedge(tran(i,j,),tran(i,j-,),);
if(jud(i,j+)) addedge(tran(i,j,),tran(i,j+,),);
addedge(tran(i,j,),tran(i,j,),);
addedge(tran(i,j,),tran(i,j,),);
}
}
int u;
fo(i,,a){
u=read();
addedge(,tran(,u,),);
}
fo(i,,b){
u=read();
addedge(tran(n,u,),n*m*+,);
}
if(sap(,n*m*+,n*m*+)==a){
printf("Yes\n");
}else{
printf("No\n");
}
}
return ;
}
2019 ccpc 秦皇岛的更多相关文章
- 【2019 CCPC 秦皇岛】J - MUV LUV EXTRA
原题: 题意: 给你两个整数a和b,再给你一个正小数,整数部分忽略不计,只考虑小数部分的循环节,对于所有可能的循环节,令其长度为l,在小数部分循环出现的长度为p,最后一个循环节允许不完整,但是缺少的部 ...
- 2019 ccpc秦皇岛
1006 (dfs) #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const dou ...
- 2019.ccpc女生赛-wfinal总结
2019ccpc女生赛离它结束有四天了,在这个期间我想了很多,想了想还是决定写这个总结.作为这个队伍唯一的一名大一队员,我很庆幸,能跟着两个学姐一起打比赛,计爱玲师姐,即将工作,张莹俐学姐.这估计都是 ...
- 2017 CCPC秦皇岛 E题 String of CCPC
BaoBao has just found a string of length consisting of 'C' and 'P' in his pocket. As a big fan of ...
- 2017 CCPC秦皇岛 A题 A Ballon Robot
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be teams parti ...
- 2018年9月28日CCPC秦皇岛站参赛总结
day1: 被中间结果超出int范围给叉了,立刻意识到了自己的弱小以及校赛出题的时候是怎么叉别人的 day2: 签到签了40分钟,谨慎一些还是很好的,机子重启耽误了一些时间 一道暴力+LCS的简单题被 ...
- 2019 CCPC wannfly winter camp Day 5
C - Division 思路:我们考虑到一点,从大往小取得顺序是不会有问题的,所以可以直接主席树,但是开不下空间,我们可以log分段求. #include<bits/stdc++.h> ...
- 2019 CCPC wannfly winter camp Day 8
E - Souls-like Game 直接线段树合并矩阵会被卡T掉,因为修改的复杂度比询问的复杂度多一个log,所以我们考虑优化修改. 修改的瓶颈在于打lazy的时候, 所以我们预处理出每个修改矩阵 ...
- ccpc秦皇岛部分题解
A. 题意:就是有一个大桌子,环绕有顺势站1~m共m个座位,n个选手坐在部分位置上.然后如果有一个人a了一道题,却没有立刻发气球给他,他产生怒气值是发气球给他的时间减去a题时间.现在有一个机器人顺时针 ...
随机推荐
- Flask开发系列之快速入门
Flask开发系列之快速入门 文档 一个最小的应用 调试模式 路由 变量规则 构造 URL HTTP 方法 静态文件 模板渲染 访问请求数据 环境局部变量 请求对象 文件上传 Cookies 重定向和 ...
- 初探CSS - 5 创建
CSS 创建 当读到一个样式表时,浏览器会根据它来格式化 HTML 文档. 如何插入样式表 插入样式表的方法有三种: 外部样式表(External style sheet) 内部样式表(Interna ...
- Hash介绍
Hash,一般翻译做"散列",也有直接音译为"哈希"的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就 ...
- Redis入门部署及持久化
软件简介 软件说明 Redis是一款开源的,ANSI C语言编写的,高级键值(key-value)缓存和支持永久存储NoSQL数据库产品. Redis采用内存(In-Memory)数据集(DataSe ...
- Delphi简介
- Linux man学习
5 man man是manual的简写,Linux求助的工具 man 命令行,如 man date 在我学习鸟哥私房菜的时候,也称man为man page 手册页入口:1 用户指令2 ...
- HTTPS的常见错误及解决方案Chrome篇
Chrome浏览器错误代码 问题原因 解决方法 NET::ERR_CERT_DATE_INVALID 网站的ssl证书有效期过期导致的 重新申请新的SSL证书 NET::ERR_CERT_COMMON ...
- mybatis简单用法
1.resultType 和 resultMap 引言: MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表 ...
- git windows下换行符问题
不同操系统下的换行符 CR回车 LF换行 Windows/Dos CRLF \r\n Linux/Unix LF \n MacOS CR \r 1.执行git config --get core.au ...
- AJAX 实例解析
AJAX 实例 为了帮助您理解 AJAX 的工作原理,我们创建了一个小型的 AJAX 应用程序: 实例 AJAX 不是新的编程语言,而是一种使用现有标准的新方法.深圳dd马达 AJAX 是与服务器交换 ...