matrix_2015_1 138 - ZOJ Monthly, January 2015
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3844
第一个,n个数,每次操作最大数和最小数都变成他们的差值,最后n个数相同时输出此时的值,暴力跑。
#include<cstdio>
int main(){
int t,n,a[];
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
while(true){
int bid=,sid=;
for(int i=;i<n;i++){
if(a[bid]<a[i]) bid=i;
if(a[sid]>a[i]) sid=i;
}
if(a[bid]==a[sid]){
printf("%d\n",a[sid]);
break;
}
a[bid]=a[sid]=a[bid]-a[sid];
}
}
}
return ;
}
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5440
第二个,n个数,每次操作可以任意选两个数把他们变成他们gcd的值。最后问几步能都变成1,且输出每步选的数的下标。方法:先求出n个数的gcd,如果不为1,输出-1.否则一定能变成全1.变的方法是,先用第一个依次和后面的操作,直至第一个数变成1,然后再用第一个数把剩下的非1的都变掉。
#include<cstdio>
#include<vector>
using namespace std;
const int M=1e5+;
typedef pair<int,int> pii;
int a[M];
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
vector<pii> ans;
int main(){
int n;
int cas=;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
int now=a[];
for(int i=;i<=n;i++){
now=gcd(now,a[i]);
}
printf("Case %d: ",cas++);
if(now>){
puts("-1");
puts("");
continue;
}
ans.clear();
for(int i=;i<=n;i++){
int now=gcd(a[],a[i]);
a[]=a[i]=now;
ans.push_back(make_pair(,i));
if(now==) break;
}
for(int i=;i<=n;i++){
if(a[i]==) continue;
ans.push_back(make_pair(,i));
}
int len=ans.size();
printf("%d\n",len);
for(int i=;i<len;i++){
printf("%d %d\n",ans[i].first,ans[i].second);
}
puts("");
}
return ;
}
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5435
第三个,52张牌,没有大小王的,输入几张,那么剩下的就是我们可以使用的,必须全用上,问有几种排列使得字典序小于他输入的。
#include<cstdio>
#include<cstring>
#define mt(a,b) memset(a,b,sizeof(a))
const int M=;
typedef long long LL;
const LL mod=1e9+;
char a[M];
int num[M];
int sheng[M];
int getval(char c){
if(c=='A') return ;
if(c=='J') return ;
if(c=='Q') return ;
if(c=='K') return ;
return c-'';
}
int s[M];
LL jc[M];
LL INV[M];
void inv_init() { //初始化%mod的乘法逆元
INV[]=;
for(int i=; i<M; i++) {
INV[i]=INV[mod%i]*(mod-mod/i)%mod;
}
}
int main(){
inv_init();
jc[]=;
for(int i=;i<M;i++){
jc[i]=jc[i-]*i%mod;
}
while(~scanf("%s",a)){
int la=strlen(a);
mt(num,);
int val;
int ls=;
for(int i=;i<la;i++){
if(a[i]==''){
val=;
i++;
}
else{
val=getval(a[i]);
}
num[val]++;
s[ls++]=val;
}
for(int i=;i<=;i++){
sheng[i]=-num[i];
}
LL ans=;
for(int i=;i<ls;i++){
for(int j=;j<s[i];j++){
if(sheng[j]==) continue;
LL tmp=jc[-ls-i-];
for(int k=;k<=;k++){
if(sheng[k]==) continue;
if(k==j){
for(int u=;u<=sheng[k]-;u++){
tmp*=INV[u];
tmp%=mod;
}
}
else{
for(int u=;u<=sheng[k];u++){
tmp*=INV[u];
tmp%=mod;
}
}
}
ans+=tmp;
ans%=mod;
}
if(sheng[s[i]]){
sheng[s[i]]--;
int sum=;
for(int j=;j<=;j++){
sum+=sheng[j];
}
if(sum==){
if(i<ls-) ans++;
break;
}
continue;
}
break;
}
printf("%lld\n",ans%mod);
}
return ;
}
end
matrix_2015_1 138 - ZOJ Monthly, January 2015的更多相关文章
- 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...
- ZOJ Monthly, January 2018 训练部分解题报告
A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...
- ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H
Bob wants to pour water Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There i ...
- ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 3910 Market ZOJ Monthly, October 2015 - H
Market Time Limit: 2 Seconds Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...
- ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F
Number Game Time Limit: 2 Seconds Memory Limit: 65536 KB The bored Bob is playing a number game ...
- ZOJ 3905 Cake ZOJ Monthly, October 2015 - C
Cake Time Limit: 4 Seconds Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...
- ZOJ 3903 Ant ZOJ Monthly, October 2015 - A
Ant Time Limit: 1 Second Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...
- ZOJ Monthly, July 2015
B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...
随机推荐
- jquery源码学习--iceDog
/** * @FileName : iceDog * @Author : PheonixHkbxoic * @Mail : hkbxoic@gmail.com * @DateTime : 2016-0 ...
- windows下 apache 二级域名相关配置
小编今天给大家总结下 windows 下 apache的二级域名的相关配置 利用.htaccess将域名绑定到子目录 下面就利用本地127.0.0.1进行测试 我们这里以 www.jobs.com 为 ...
- ajaxFileUpload增加附加参数
直接说方法: $.ajaxFileUpload({ data:{"a":123,"b":456};//附加参数,json格式 }); 然后在ajaxFileUp ...
- 【深入比较ThreadLocal模式与synchronized关键字】
[深入比较ThreadLocal模式与synchronized关键字]ThreadLocal模式与synchronized关键字都是用于处理多线程并发访问变量的问题.只是两者处理问题的角度和思路不同. ...
- IOS学习3
@property属性使用 copy:NSString strong: 一般对象 weak: UI空间 assign:基本数据类型 retain: (对象,先上述类型使用) id 万能指针. id缺点 ...
- java基础笔记
1. 成员变量会自动的进行初始化,但是局部变量不会: 2. equals传引用值,==传地址值:当一个对象是引用类型时,就必须使用equals进行比较. 3. 继承:实现代码的复用,继承关系以一种验证 ...
- 小课堂week13 Clean Code Part2
Clean Code Part2 对象与数据结构 首先让我们进行一个严肃的思考,对象与数据结构的区别在哪里? 如下两段代码分别用数据结构和对象的方法来描述了一个Point. public class ...
- Python超简单的HTTP服务器
Python超简单的HTTP服务器 安装了python就可以 python -m SimpleHTTPServer 执行这一个命令即可实现一个HTTP服务器,将当前目录设为HTTP服务目录,可以通过h ...
- swift 2
... ..< func a(inout a) //by ref use &xx Parameters passed to functions are constants by de ...
- arcgis离海距离的计算
1.利用arctoolbox——要素——面转线工具,将县界提取出来. 2.对线要素编辑,利用“分割”工具对边界截断,而后融合成一条海岸线 3.利用分析工具——领域分析——近邻分析计算点到海岸线要素的距 ...