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后拿,依次拿,每次可以拿任意一 ...
随机推荐
- WordPress 主题开发 - (十三) Archive模板 待翻译
What archive.php does (and all its related templates) is show posts based on a select criteria. A da ...
- Java实现抽奖游戏
代码如下: import java.io.*; public class PresentDemo { /** * @param args */ public static void main(Stri ...
- 点击后弧形展开的炫酷菜单--第三方开源-- CircularFloatingActionMenu(一)
CircularFloatingActionMenu在github上项目主页地址:https://github.com/oguzbilgener/CircularFloatingActionMenu ...
- PHP取当前页面完整URL地址
#测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br> ...
- SQL语句的执行顺序
一.sql语句的执行顺序 (8)SELECT (9) DISTINCT (11) <TOP_specification> <select_list> (1) FROM < ...
- <bootstrap>bs2和3的区别</bootstrap>
实验室的list网站开始动工了,准备打算用bootstrap作布局. 大前天去本部停了长html5峰会大连站的讲演,着急往回赶,很多感兴趣的东西都没有听到,但是还是了解了一些html5的新特性 电脑端 ...
- angularjs2 学习笔记(六) Form
Angular 2 Form表单 在angular2 form表单中我们需要了解表单数据绑定.数据验证.数据提交等内容,在下面的示例中并没有实际提交到后台,这部分内容在今后webapi中加以练习. 表 ...
- C基础 数据序列化简单使用和讨论
前言 C中对序列化讨论少, 因为很多传输的内容都有自己解析的轮子. 对于序列化本质是统一编码, 统一解码的方式. 本文探讨是一种简单的序列化方案. 保证不同使用端都能解析出正确结果. 在文章一开始, ...
- unp.h
unp.h #ifndef _UNP_H_ #define _UNP_H_ #include <unistd.h> #include <stdio.h> #include &l ...
- SQLserver使用映射表进行数据相关操作
基本需求: 老数据有老数据的顺序编码规则,新数据有新数据的顺序编码规则,但是老数据的编码还是要更新相应的东西,新数据也得实时更新,在新数据中已经用新编码规则对老数据对进行编码,在上报表中既要新增新数据 ...