1001 Interesting Integers

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=4731

给你[a,b]区间,问有几个数是有趣的数(数字只有一个数不同的),臣妾不行;

1002 Longest Prefix

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=3559

1003 Count Color

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6036

t种颜色上到原色为颜色1的板子上面。线段树

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
ll add[maxn<<];
ll ans[maxn<<];
void update(int rt)
{
ans[rt]=ans[rt<<]|ans[rt<<|];
}
void Push(int rt)
{
if(add[rt])
{
add[rt<<]=add[rt];
add[rt<<|]=add[rt];
ans[rt<<]=add[rt];
ans[rt<<|]=add[rt];
add[rt]=;
}
}
void buildtree(int left,int right,int rt)
{
add[rt]=;
if(left==right)
{
ans[rt]=;
return;
}
int mid=(left+right)>>;
buildtree(left,mid,rt<<);
buildtree(mid+,right,rt<<|);
update(rt);
}
void updatetree(int a,int b,int c,int Left,int Right,int rt)
{
if(a<=Left&&b>=Right)
{
add[rt]=<<(c-);
ans[rt]=<<(c-);
return;
}
Push(rt);
int mid=(Left+Right)>>;
if(a<=mid) updatetree(a,b,c,Left,mid,rt<<);
if(mid<b) updatetree(a,b,c,mid+,Right,rt<<|);
update(rt);
}
ll query(int a,int b,int Left,int Right,int rt)
{
if(a<=Left&&b>=Right) return ans[rt];
Push(rt);
int mid=(Left+Right)>>;
ll res=;
if(a<=mid) res|=query(a,b,Left,mid,rt<<);
if(mid<b) res|=query(a,b,mid+,Right,rt<<|);
return res;
}
int main()
{
int L,T,O;scanf("%d%d%d",&L,&T,&O);
buildtree(,L,);
while(O--)
{
getchar();
char ch;scanf("%c",&ch);
if(ch=='C')
{
int a,b,c;scanf("%d%d%d",&a,&b,&c);
if(a>b) swap(a,b);
updatetree(a,b,c,,L,);
}
else{
int a,b;scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
ll res=query(a,b,,L,);
ll num=;
while(res)
{
if(res&) num++;
res>>=;
}
printf("%lld\n",num);
}
}
}

1004 Get Many Persimmon Trees

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6045

二维树状数组,以(s,t)的矩形暴力找过去,得到最大的ans。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 105
int ma[N][N];
int n,m;
inline int lowbit(int x){return x&-x;}
void updata(int x,int y)
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=m;j+=lowbit(j)) ma[i][j]++;
}
int query(int x,int y)
{
int res=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j)) res+=ma[i][j];
return res;
}
int main()
{
int T;
while(~scanf("%d",&T),T)
{
scanf("%d%d",&n,&m);
memset(ma,,sizeof(ma));
while(T--)
{
int a,b;scanf("%d%d",&a,&b);
updata(a,b);
}
int s,t;scanf("%d%d",&s,&t);
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
int upi=i,upj=j,downi=i+s-,downj=j+t-;
if(downi>n||downj>m) continue;
int sum=query(upi-,upj-)+query(downi,downj)-query(downi,upj-)-query(upi-,downj);
ans=ans>sum?ans:sum;
}
printf("%d\n",ans);
}
}

1005 Travelling

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6062

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 60005
int mp[][],n,m,ans,dp[][N];
int in[],three[];
void init(int n)
{
for(int i=;i<n;i++)
{
for(int j=;j<in[n];j++)
dp[i][j]=-;
for(int j=;j<n;j++)
mp[i][j]=-;
}
}
int arr(int three[],int sum)
{
int res=;
for(int i=;i<n;i++)
{
three[i]=sum%;
sum/=;
if(three[i]) res++;
}
return res;
}
void bfs()
{
for(int kk=;kk<in[n];kk++)
{
int k=arr(three,kk);
for(int i=;i<n;i++)
{
if(three[i])
{
if(k==) dp[i][kk]=;
if(dp[i][kk]==-) continue;
if(k==n)
{
if(ans==-) ans=dp[i][kk];
else ans=min(ans,dp[i][kk]);
}
for(int j=;j<n;j++)
{
if(i!=j&&three[j]<&&mp[i][j]!=-)
{
int mark=kk+in[j];
if(dp[j][mark]==-) dp[j][mark]=dp[i][kk]+mp[i][j];
else dp[j][mark]=min(dp[i][kk]+mp[i][j],dp[j][mark]);
}
}
}
}
}
}
int main()
{
in[]=;
for(int i=;i<=;i++) in[i]=in[i-]*;
while(~scanf("%d%d",&n,&m))
{
init(n);
while(m--)
{
int a,b,c;scanf("%d%d%d",&a,&b,&c);
a--,b--;
if(mp[a][b]!=-) mp[a][b]=mp[b][a]=min(mp[a][b],c);
else mp[a][b]=mp[b][a]=c;
}
ans=-;
bfs();
printf("%d\n",ans);
}
}

1006 A/B

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6065

(A/B)%MOD->(A%MOD)*(B-1%MOD)

这里用了求出m的欧拉函数值再进行一次快速幂f(b,phi[M]-1)求逆元

 #include<bits/stdc++.h>
using namespace std;
const int M=;
typedef long long ll;
ll phi[];
void euler()
{
for(int i=;i<=M;++i)
phi[i]=i;
for (int i=;i<=M;i++)
if (phi[i]==i)
for (int j=i;j<=M;j+=i)
phi[j]=phi[j]/i*(i-);
}
ll f(ll a,ll b)
{
ll res=,x=a%M;
while(b)
{
if(b&) res=(res*x)%M;
b>>=;
x=x*x%M;
}
return res;
}
int main()
{
euler();
int t;scanf("%d",&t);
while(t--)
{
ll n,b;scanf("%lld%lld",&n,&b);
printf("%lld\n",n*f(b,phi[M]-)%M);
}
}

拓展欧几里得算法,a*x+b*y=GCD,当a==GCD,b==0时停止查找,可推出最后状态a*1+b*0==GCD。前后等式分别为a*x+b*y=gcd、b*x1+(a%b)*y1=gcd,补上条件递归。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=;
ll ans,re;
void e_gcd(ll a,ll b)
{
if(b==)
{
ans=,re=;
return;
}
e_gcd(b,a%b);
ll temp=ans;
ans=re;
re=temp-a/b*re;
}
int main()
{
int t;scanf("%d",&t);
while(t--)
{
ll n,b;scanf("%lld%lld",&n,&b);
e_gcd(b,M);
ans<?ans+=M:ans+=;
printf("%lld\n",n*ans%M);
}
}

1007 Road Construction

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6085

缩点,(叶子节点+1)/2

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1005
vector<int> G[N];
int n,r,low[N],degree[N],mp[N][N],cnt;
void init()
{
for(int i=;i<=n;i++) G[i].clear();
memset(low,,sizeof(low));
memset(degree,,sizeof(degree));
memset(mp,,sizeof(mp));
}
void dfs(int u,int x)
{
int l=G[u].size();
low[u]=cnt++;
for(int i=;i<l;i++)
{
int v=G[u][i];
if(v==x) continue;
if(!low[v]) dfs(v,u);
low[u]=min(low[u],low[v]);
}
}
int tarjan()
{
for(int i=;i<=n;i++)
{
int l=G[i].size();
for(int j=;j<l;j++)
if(low[i]!=low[G[i][j]]) degree[low[i]]++;
}
int res=;
for(int i=;i<=n;i++)
if(degree[i]==) res++;
return res;
}
int main()
{
scanf("%d%d",&n,&r);
init();
while(r--)
{
int a,b;scanf("%d%d",&a,&b);
if(mp[a][b]) continue;
mp[a][b]=mp[b][a]=;
G[a].push_back(b),G[b].push_back(a);
}
cnt=;
dfs(,);
int res=tarjan();
printf("%d\n",(res+)/);
}

1008 Currency Exchange

http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6097

spfa算法,判断是否存在环路。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 105
double ma1[N][N],ma2[N][N],ans[N];
int n,m,s,a,b;
int vis[N];
double v,x_ab,x_ba,y_ab,y_ba;
bool spfa()
{
ans[s]=v;
vis[s]=;
queue<int> qu;
qu.push(s);
while(!qu.empty())
{
int node=qu.front();
qu.pop();
vis[node]=;
for(int i=;i<=n;i++)
{
if(ans[i]<(ans[node]-ma2[node][i])*ma1[node][i])
{
ans[i]=(ans[node]-ma2[node][i])*ma1[node][i];
if(ans[s]>v) return true;
if(!vis[i]) qu.push(i),vis[i]=;
}
}
}
return false;
}
void init()
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
ma1[i][j]=;
ma2[i][j]=ma1[i][j]=;
}
}
}
int main()
{
scanf("%d%d%d%lf",&n,&m,&s,&v);
init();
for(int kk=;kk<m;kk++)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&x_ab,&y_ab,&x_ba,&y_ba);
ma1[a][b]=x_ab,ma2[a][b]=y_ab;
ma1[b][a]=x_ba,ma2[b][a]=y_ba;
}
if(spfa()) printf("YES\n");
else printf("NO\n");
}

2019/11/09 TZOJ的更多相关文章

  1. 2019/11/02 TZOJ

    1001 ShaoLin http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6003 标记一下i ...

  2. 2019.07.09 纪中_B

    错失AK记 2019.07.09[NOIP提高组]模拟 B 组 明明今天的题都很水,可就是没蒟蒻. 写题的时候: T0一眼高精(结果没切)T1看到2啊8啊果断转二进制观察,发现都是左移几位然后空出的位 ...

  3. AWS re:Invent(2019.01.09)

    时间:2019.01.09地点:北京国际饭店

  4. ACM阶段总结(2016.10.07-2016.11.09)

    来这里也有一段时间了…… 总感觉自己练得不是很有效. 最近的一些行动就是不断做比赛,然后不停地补,但是感觉这样像只无头苍蝇,没有效果,学不到什么真正的东西. 最近开始打算补专题,做做codeforce ...

  5. EOJ Monthly 2019.11 E. 数学题(莫比乌斯反演+杜教筛+拉格朗日插值)

    传送门 题意: 统计\(k\)元组个数\((a_1,a_2,\cdots,a_n),1\leq a_i\leq n\)使得\(gcd(a_1,a_2,\cdots,a_k,n)=1\). 定义\(f( ...

  6. [New!!!]欢迎大佬光临本蒟蒻的博客(2019.11.27更新)

    更新于2019.12.22 本蒟蒻在博客园安家啦!!! 本蒟蒻的博客园主页 为更好管理博客,本蒟蒻从今天开始,正式转入博客园. 因为一些原因,我的CSDN博客将彻底不会使用!!!(带来不便,敬请谅解) ...

  7. 2019.11.9 csp-s 考前模拟

    2019.11.9 csp-s 考前模拟 是自闭少女lz /lb(泪奔 T1 我可能(呸,一定是唯一一个把这个题写炸了的人 题外话: 我可能是一个面向数据编程选手 作为一个唯一一个写炸T1的人,成功通 ...

  8. 2021.11.09 P4824 [USACO15FEB]Censoring S与P3121 [USACO15FEB]Censoring G(KMP&&AC自动机)

    2021.11.09 P4824 [USACO15FEB]Censoring S与P3121 [USACO15FEB]Censoring G(KMP&&AC自动机) https://w ...

  9. 2021.11.09 P2292 [HNOI2004]L语言(trie树+AC自动机)

    2021.11.09 P2292 [HNOI2004]L语言(trie树+AC自动机) https://www.luogu.com.cn/problem/P2292 题意: 标点符号的出现晚于文字的出 ...

随机推荐

  1. 知乎使用selenium反爬虫的解决方案

    from selenium.webdriver import Chrome from selenium.webdriver import ChromeOptions option = ChromeOp ...

  2. 小白学Python(10)——pyecharts 绘制仪表图 Gauge

    from pyecharts import options as opts from pyecharts.charts import Gauge, Page gauge=( Gauge() .add( ...

  3. Linux下CMake简明教程

    转载地址:https://blog.csdn.net/whahu1989/article/details/82078563 CMake是开源.跨平台的构建工具,可以让我们通过编写简单的配置文件去生成本 ...

  4. 从ES6重新认识JavaScript设计模式: 装饰器模式

    1 什么是装饰器模式 向一个现有的对象添加新的功能,同时又不改变其结构的设计模式被称为装饰器模式(Decorator Pattern),它是作为现有的类的一个包装(Wrapper). 可以将装饰器理解 ...

  5. 详解 vue 双向数据绑定的原理,并实现一组双向数据绑定

    1:vue 双向数据绑定的原理: Object.defineProperty是ES5新增的一个API,其作用是给对象的属性增加更多的控制Object.defineProperty(obj, prop, ...

  6. python实现不同条件下单据体的颜色不一样,比如直接成本分析表中关闭的细目显示为黄色

    #引入clr运行库 import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee ...

  7. linux--基础知识4

    #当前已什么用户登陆,创建的目录或文件,他的属组和主就是谁 #用户对目录拥有的几种权限 # ll -d查看目录当前权限信息 #r:可以查看该目录下的子文件名,子目录 #w:可以在该目录下创建,删除,重 ...

  8. 封装操作mysql、redis

    封装操作mysql: import pymysql class MyDb: def __init__(self,host,password,user,db,port=3306,charset='utf ...

  9. Spring中都用到了哪些设计模式

    JDK 中用到了那些设计模式?Spring 中用到了那些设计模式?这两个问题,在面试中比较常见.我在网上搜索了一下关于 Spring 中设计模式的讲解几乎都是千篇一律,而且大部分都年代久远.所以,花了 ...

  10. 【leetcode】1080. Insufficient Nodes in Root to Leaf Paths

    题目如下: Given the root of a binary tree, consider all root to leaf paths: paths from the root to any l ...