noip模拟赛#23
T1:n个元素的集合。要求取出k个子集,使得k个子集交集为空集。问有多少中取法。
=>推了很久。。。想的是从k等于2的情况推到k等于3的情况。。。。然后k=2推出来了k=3也推出来了。。。推了挺久的。。。(k+1)^N。然后yyl说错了。。。每一个元素有2^k-1中选择。所以答案为(2^k-1)^n
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
const int inf=0x7f7f7f7f;
const int mod=1e9+7;
ll pw(ll a,ll b){
ll ans=(a%=mod);--b;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod;b>>=1;
}
return ans;
}
int main(){
freopen("sets.in","r",stdin);freopen("sets.out","w",stdout);
ll n,k;scanf("%lld%lld",&n,&k);
if(k==1) puts("1");
else printf("%lld\n",pw(pw(2,k)-1+mod,n));
fclose(stdin);fclose(stdout);
return 0;
}
T2:n=1e9,k=1e9。求n个元素的第k个排列有多少个数满足x为index数并且a[x]也为index数。index数为只由4和7组成的数。
=>康托展开就可以了。。。然而我康托展开差点写萎了TAT
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int inf=0x7f7f7f7f;
const int nmax=1e5+5;
ll f[nmax];int t[nmax],ans[nmax];bool vis[nmax];
bool check(int x,int y){
while(x){
if(x%10!=4&&x%10!=7) return 0;
x/=10;
}
while(y){
if(y%10!=4&&y%10!=7) return 0;
y/=10;
}
return 1;
}
int main(){
freopen("permutation.in","r",stdin);freopen("permutation.out","w",stdout);
f[1]=1;f[2]=1;rep(i,3,20) f[i]=f[i-1]*(i-1);
t[1]=4;t[2]=7;int cur=0,cnt=2;
rep(i,1,8){
rep(j,cur+1,cur+(1<<i)) t[++cnt]=t[j]*10+4,t[++cnt]=t[j]*10+7;
cur+=(1<<i);
} int n=read(),k=read();
if(n<=18&&k>f[n+1]||!k) puts("-1");
else{
--k;
for(cur=1;cur<=n+1;++cur) if(k<f[cur]) break;--cur;
dwn(i,cur,1){
int tmp=k/f[i]+1,pos=0;k%=f[i];
rep(j,1,cur) if(!vis[j]){
if(++pos==tmp) {
pos=j;vis[j]=1;break;
}
}
ans[cur-i+1]=pos;
}
int res=0;
rep(i,1,cnt) if(t[i]>n-cur) break;else res++;
rep(i,1,cur) if(check(n-cur+i,n-cur+ans[i])) res++;
printf("%d\n",res);
}
fclose(stdin);fclose(stdout);
return 0;
}
T3:题意有误?也没有solution。。。
noip模拟赛#23的更多相关文章
- NOIP 模拟赛 23 T4 大逃亡O(二分+广搜)(∩_∩)O
题目描述 给出数字N(1≤N≤10000),X(1≤x≤1000),Y(1≤Y≤1000),代表有N个敌人分布一个X行Y列的矩阵上,矩形的行号从0到X-1,列号从0到Y-1再给出四个数字x1,y1,x ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
随机推荐
- 读《JavaScript权威指南》笔记(一)
1.Number() parseInt() parseFloat() 如果通过Number()转换函数传入一个字符串,它会试图将其转换为一个整数或浮点数直接量,这个方法只能基于十进制数进行转换,并 ...
- oracle分页计算公式
//page是页数,rows是显示行数 int page=2; int rows=5; List<Articles> list=a.select(page*rows+1,(page-1)* ...
- uva 1153 顾客是上帝(贪心)
uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...
- springboot jpa mongodb 多条件分页查询
public Page<Recorded> getRecordeds(Integer page, Integer size, Recorded recorded) { if (page&l ...
- module.exports 和 export default
CommonJS模块规范和ES6模块规范完全是两种不同的概念 CommonJS模块规范 Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一 ...
- 简单的vue.js的表单提交数据至flask然后数据库入库,再将表里面的数据展示在网页
一.先在数据库中创建表格 在mysql中建users库并建立一个含有ID,username,email三个字段的user表 二.去vue的组件里面写页面的表单代码,注意form标签里的action需要 ...
- 008-数据类型(Dictionary)
数据类型(Dictionary) 一.定义 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号:分割,每个键值对之间用逗号,分割,整个字典包括在花括 ...
- C# AD 验证登陆
using System.DirectoryServices; using System.DirectoryServices.AccountManagement; using (DirectoryEn ...
- 洛谷P4891 序列 || 膜法阵,魔法阵
https://www.luogu.org/problemnew/show/P4891 一道几乎一样的题http://210.33.19.103/contest/1130/problem/3 题面ht ...
- 匿名内部类(new类时覆盖类中方法)
public class Person { private String name ; protected String getName() { return name; } public void ...