Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A
A. Distinct Digits
超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每一位的数字不相同,找出满足要求的最小的那个数输出,没有找到就输出-1;
#include<bits/stdc++.h>
using namespace std;
bool check(int n){
int vis[]={};
while(n){
if(!vis[n%]) vis[n%]=;
else return false;
n/=;
}
return true;
}
int main()
{
int l,r;
cin>>l>>r;
for(int i = l;i <=r;++i){
if(check(i)){
cout<<i<<endl;return ;
}
}
cout<<"-1"<<endl;
return ;
}
AC代码
https://codeforces.com/contest/1228/problem/B
B. Filling the Grid
也很简单,,自己读题没读清导致前面白wa了好几发。给一个n*m的grid,然后告诉你每一行每一列从边界处开始连续的黑块个数,然后求满足这个条件的有多少种情况,输出结果mod1e9+7。
然后要注意,如果没有方案数是输出0的。
因为h,w<=1e3,所以构建个二维数组就好了,在连续黑色块的位置标记1,后一位还有空位的话标-1,-1表示这个地方不能变黑,如果标1和-1重复了,那么方案数就是0,如果可以把这个基础的图构造出来的话,统计一下0的个数ans,输出2的ans次方就好了(因为0可填黑可填白)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
int mp[][];
long long power(long long a,long long b)///a是底数,b是次幂
{
long long ans=;
for(;b!=;b>>=)
{
if(b&) ans=(long long)ans*a%mod;
a=(long long)a*a%mod;
}
return ans;
} int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
int a;cin>>a;
for(int j=;j<=a;j++)
{
mp[i][j]=;
}
mp[i][a+]=-;
}
int f=;
for(int i=;i<=m;i++)
{
int a;cin>>a;
for(int j=;j<=a;j++)
{
if(mp[j][i]==-) f=;
mp[j][i]=;
}
if(mp[a+][i]==) f=;
mp[a+][i]=-;
}
if(f==)
cout<<<<endl;
else
{
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(mp[i][j]==)
ans++;
cout<<power(,ans)<<endl;
}
}
AC代码
https://codeforces.com/contest/1230/problem/C
C. Primes and Multiplication
写这道题的时候疯狂挨骂emmm,lj好好反思。
根据题目定义把要求的东西展开,然后要用到的一个结论就是求1-n中质因子x的个数是求Σ(n/x^k)(k=1,2,3...)
还学到了个求质因子的方法? 害...不会的东西太多了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
ll sq(ll a,ll b){
ll cnt=;
while(b){
if(b&)cnt=cnt%mod*a%mod;
a=a*a%mod;
b>>=;
}
return cnt%mod;
}
vector<ll>s;
int main(){
ll ans= ,x,n;
cin>>x>>n;
for(ll i = ;i *i<= x;++i){
if(x%i==)s.push_back(i);
while(x%i==)x/=i;
}
s.push_back(x);
for(int i = ;i< s.size();++i){
if(s[i]==) continue;
ll sum=,temp=s[i],a=s[i];
while(temp<=n){
sum+=n/temp;
if(temp>n/a)break;
temp*=a;
} ans=ans*sq(a,sum)%mod;ans%=mod;
}
cout<<ans<<endl;
return ;
}
AC代码
https://codeforces.com/contest/1228/problem/D
D. Complete Tripartite
给n个点m条边,然后构造三个顶点集,其中任一顶点集内的顶点两两之间没有边,然后该顶点集的任一顶点都和不属于这个顶点集的所有点有边。
如果可以就输出每个顶点所属的集合,不可以就输出-1;
emmmmmm,然后按照题意写就好了,先全部放在集合1,然后和集合1有边的就去集合2,然后集合2内部有边的就放到集合3去,再检查集合内部有没有连接的边。
如果都没问题了之后再检查每个点是否和其他不属于它集合的点有边,那么就想办法检查一遍和她连接的点在另外两个集合的个数是不是 等于另外两个集合的顶点数
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+;
vector<int>s[N];
int pre[N],cnt1=,cnt2=,cnt3=,temp1,temp2,temp3;
struct ac{
int x,y;
}a[];
int main()
{
int n,m;
cin>>n>>m;
for(int i = ;i <=n;++i)pre[i]=;cnt1=n;
for(int i = ;i <m;++i){
cin>>a[i].x>>a[i].y;
s[a[i].x].push_back(a[i].y);s[a[i].y].push_back(a[i].x);
} for(int i = ;i <= n; ++i){
if(s[i].size()<){cout<<"-1"<<endl;return ;}
for(int j = ;j < s[i].size();++j){
if(pre[i]==)
if(pre[s[i][j]]==)pre[s[i][j]]=,cnt1--,cnt2++;
}
}
for(int i = ;i <= n;++i){
for(int j = ;j <s[i].size();++j){
if(pre[i]==)
if(pre[s[i][j]]==)pre[s[i][j]]=,cnt2--,cnt3++;
}
}
if(cnt1==||cnt2==||cnt3==){
cout<<"-1"<<endl;return ;
} for(int i = ;i <=n;++i){
temp1=temp2=temp3=;
for(int j = ;j < s[i].size();++j){
if(pre[i]==pre[s[i][j]]){
cout<<"-1"<<endl;return ;
}
if(pre[i]==){
if(pre[s[i][j]]==)temp2++;
else if(pre[s[i][j]]==)temp3++;
}
else if(pre[i]==){
if(pre[s[i][j]]==)temp1++;
else if(pre[s[i][j]]==)temp3++;
}
else if(pre[i]==){
if(pre[s[i][j]]==)temp2++;
else if(pre[s[i][j]]==)temp1++;
}
}
if(pre[i]==){
if(temp2<cnt2||temp3<cnt3){
cout<<"-1"<<endl;return ;
}
}
else if(pre[i]==){
if(temp1<cnt1||temp3<cnt3){
cout<<"-1"<<endl;return ;
}
}
else if(pre[i]==){
if(temp2<cnt2||temp1<cnt1){
cout<<"-1"<<endl;return ;
}
}
}
for(int i = ;i <=n;++i)cout<<pre[i]<<" ";cout<<endl;
}
AC代码
emmmm我也不清楚为啥这个题这么暴力的写都能过。。可能这就是div3吧(真实(然而我写了很久
Codeforces Round #589 (Div. 2) (e、f没写)的更多相关文章
- Codeforces Round 212 Div 2 报告(以前没写完,现在也没心情补了,先就这样吧)
A. Two Semiknights Meet 题目大意:有一个8x8的棋盘,上面放有两个骑士,骑士以“田字”的方式走.每个方格都被定义为good或者bad,问骑士能否在good的格子中相遇? 由于骑 ...
- Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...
- Codeforces Round #573 (Div. 1) 差F
Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round 589 (Div. 2) 题解
Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- Codeforces Round #346 (Div. 2) E F
因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
- Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)
链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...
随机推荐
- PHP教程-反序列化的方法
序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性.兄弟连PHP培训() 1. ...
- ELEMENT-UI 封装el-table 局部刷新row
//关于封装的el-table行数据更新后如何局部更新row row.status=status; this.$set(this.$refs.elTable.$data.tableData,index ...
- 《python cookbook》学习笔记
2016.5.3 第8章 类与对象 8.1 改变对象的字符串显示 __str__ 和 __repr__ %s 和 %r,提到了eval,我没有用过 8.2 自定义字符串的格式化 __forma ...
- JDK_API剖析之java.net包
为实现网络应用程序提供类.(按照字母顺序排序) 1.Authenticator 抽象类 自1.2开始有 无父类和接口 Authenticator 类表示懂得如何获得网络连接验证的对象.通常,它通过提示 ...
- linux下nohup日志切割方案
1.nohup命令解释: a.语法:nohup [command] [args] [&] b.说明:nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,忽略所有挂 ...
- Windows下安装jdk
1. 下载安装包:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2. 双击e ...
- Spark指标项监控
监控配置 spark的监控主要分为Master.Worker.driver.executor监控.Master和Worker的监控在spark集群运行时即可监控,Driver和Excutor的监控需要 ...
- php的intval函数
PHP intval() 函数 PHP 可用的函数PHP 可用的函数 intval() 函数用于获取变量的整数值. intval() 函数通过使用指定的进制 . PHP , PHP , PHP 语法 ...
- 函数-this
1.this. 解析器在调用函数的时候,每次都会向函数内部传递进一个隐含的参数(即this): this指向一个对象,这个对象称为函数执行的上下文对象.根据函数的调用方式的不同,this会指向不同的对 ...
- snmpEngineBoots & snmpEngineID数据存储到非易失性存储设备
#include <stdio.h> #include <stdlib.h> #include <string.h> int regenerateID() { ; ...