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 秦皇岛的更多相关文章

  1. 【2019 CCPC 秦皇岛】J - MUV LUV EXTRA

    原题: 题意: 给你两个整数a和b,再给你一个正小数,整数部分忽略不计,只考虑小数部分的循环节,对于所有可能的循环节,令其长度为l,在小数部分循环出现的长度为p,最后一个循环节允许不完整,但是缺少的部 ...

  2. 2019 ccpc秦皇岛

    1006 (dfs) #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const dou ...

  3. 2019.ccpc女生赛-wfinal总结

    2019ccpc女生赛离它结束有四天了,在这个期间我想了很多,想了想还是决定写这个总结.作为这个队伍唯一的一名大一队员,我很庆幸,能跟着两个学姐一起打比赛,计爱玲师姐,即将工作,张莹俐学姐.这估计都是 ...

  4. 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 ...

  5. 2017 CCPC秦皇岛 A题 A Ballon Robot

    The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be  teams parti ...

  6. 2018年9月28日CCPC秦皇岛站参赛总结

    day1: 被中间结果超出int范围给叉了,立刻意识到了自己的弱小以及校赛出题的时候是怎么叉别人的 day2: 签到签了40分钟,谨慎一些还是很好的,机子重启耽误了一些时间 一道暴力+LCS的简单题被 ...

  7. 2019 CCPC wannfly winter camp Day 5

    C - Division 思路:我们考虑到一点,从大往小取得顺序是不会有问题的,所以可以直接主席树,但是开不下空间,我们可以log分段求. #include<bits/stdc++.h> ...

  8. 2019 CCPC wannfly winter camp Day 8

    E - Souls-like Game 直接线段树合并矩阵会被卡T掉,因为修改的复杂度比询问的复杂度多一个log,所以我们考虑优化修改. 修改的瓶颈在于打lazy的时候, 所以我们预处理出每个修改矩阵 ...

  9. ccpc秦皇岛部分题解

    A. 题意:就是有一个大桌子,环绕有顺势站1~m共m个座位,n个选手坐在部分位置上.然后如果有一个人a了一道题,却没有立刻发气球给他,他产生怒气值是发气球给他的时间减去a题时间.现在有一个机器人顺时针 ...

随机推荐

  1. Ajax轮询请求

    Ajax轮询请求 什么是轮询? 轮询(polling):客户端按规定时间定时向服务端发送ajax请求,服务器接到请求后马上返回响应信息并关闭连接. Ajax轮询需要服务器有很快的处理速度与快速响应. ...

  2. pause模块

    pause模块:暂停脚本执行 # ansible-doc -s pause- name: Pause playbook execution pause: minutes: // 暂停的真实分钟数 pr ...

  3. java高并发核心要点|系列3|锁的底层实现原理|ABA问题

    继续讲CAS算法,上篇文章我们知道,CAS算法底层实现,是通过CPU的原子指令来实现. 那么这里又有一个情景: 话说,有一个线程one从内存位置V中取出A,这时候另一个线程two也从内存中取出A,并且 ...

  4. mysql忘记密码如何重置密码,以及修改root密码的三种方法

    1.先将MySQL停止. 命令:systemctl  stop mysqld       #停掉MySQL 命令:systemctl status mysqld         #查看状态 2.然后跳 ...

  5. idea+maven3.6.1构建maven工程报PKIX:unable to find valid certification path to requested target

    转载于  https://www.cnblogs.com/xiaoping1993/p/9717649.html 注意可能在idea工具执行java命令提示找不到类,返回类的最上层包路径 然后再执行j ...

  6. 【转】encodeURI和decodeURI方法

    为什么要两次调用encodeURI来解决乱码问题 https://blog.csdn.net/howlaa/article/details/12834595 请注意 encodeURIComponen ...

  7. mysql 8.0.16 单主 mgr搭建

    mysql 8.0.16 单主 mgr搭建 环境介绍: 192.168.142.142 db142192.168.142.143 db143192.168.142.145 db145 1.安装依赖包 ...

  8. 浅谈Java回收对象的标记和对象的二次标记过程_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 一.对象的标记 1.什么是标记?怎么标记? 第一个问题相信大家都知道,标记就是对一些已死的对象打上记号,方便垃圾收集器的 ...

  9. 【NOIP2016提高A组模拟9.9】总结

    第一题,题面很不错,正解是分治,不过用ljj水法也可以轻松的所过去. 第二题,本来以为是个有向无环图, 结果搞了半天才发现,事实并不是这样的,于是暂时弃疗, 接着在最后的40分中,某人大喊:哦原来是t ...

  10. 【leetcode】1201. Ugly Number III

    题目如下: Write a program to find the n-th ugly number. Ugly numbers are positive integers which are div ...