水题

B - Minimum’s Revenge

There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes.

Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?

InputThe first line contains only one integer T (T≤100), which indicates the number of test cases.

For each test case, the first line contains only one integer n (2≤n≤109), indicating the number of vertices.

OutputFor each test case, output one line "Case #x:y",where x is
the case number (starting from 1) and y is the total weight of the
minimum spanning tree.

Sample Input

2
2
3

Sample Output

Case #1: 2
Case #2: 5

Hint

In the second sample, the graph contains 3 edges which are (1, 2, 2), (1, 3, 3) and (2, 3, 6). Thus the answer is 5.
 #include<stdio.h>
int main()
{
int t;
long long ans;
scanf("%d",&t);
int v=;
while(t--)
{
long long n;
scanf("%lld",&n); ans=(n+)*(n-)/; printf("Case #%d: %lld\n",++v,ans); }
return ;
}

C - Mr. Frog’s Problem

One day, you, a clever boy, feel bored in your math class, and then fall asleep without your control. In your dream, you meet Mr. Frog, an elder man. He has a problem for you.

He gives you two positive integers A and B, and your task is to find all pairs of integers (C, D), such that A≤C≤B,A≤D≤B and AB+BA≤CD+DC

 

Inputfirst line contains only one integer T (T≤125), which indicates the number of test cases. Each test case contains two integers A and B (1≤A≤B≤1018).OutputFor each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then in a new line, print an integer s indicating the number of pairs you find.

In each of the following s lines, print a pair of integers C and D.
pairs should be sorted by C, and then by D in ascending order.

Sample Input

2
10 10
9 27

Sample Output

Case #1:
1
10 10
Case #2:
2
9 27
27 9

 #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
long long a,b;
long long cas=;
while(t--)
{
scanf("%lld%lld",&a,&b);
printf("Case #%lld:\n",cas++);
if(a==b)
{
printf("1\n",a,b);
printf("%lld %lld\n",a,b);
}
else
{
printf("2\n",a,b);
printf("%lld %lld\n",a,b);
printf("%lld %lld\n",b,a);
} }
}


D - Mr. Frog’s Game

One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese).

In this game, if you can draw at most three horizontal or vertical
head-and-tail-connected lines over the empty grids(the lines can be out
of the whole board) to connect two non-empty grids with the same symbol
or the two non-empty grids with the same symbol are adjacent, then you
can change these two grids into empty and get several more seconds to
continue the game.

Now, Mr. Frog starts a new game (that means there is no empty grid
in the board). If there are no pair of grids that can be removed
together,Mr. Frog will say ”I’m angry” and criticize you.

Mr. Frog is battle-scarred and has seen many things, so he can
check the board in a very short time, maybe one second. As a Hong Kong
Journalist, what you should do is to check the board more quickly than
him, and then you can get out of the room before Mr. Frog being angry.

InputThe first line contains only one integer T (T≤500), which indicates the number of test cases.

For each test case, the first line contains two integers n and m (1≤n,m≤30).

In the next n lines, each line contains m integers,  j-th number in
the i-th line means the symbol on the grid(the same number means the
same symbol on the grid).

OutputFor each test case, there should be one line in the output.

You should output “Case #x: y”,where x is the case number(starting
from 1), and y is a string representing the answer of the question. If
there are at least one pair of grids that can be removed together, the y
is “Yes”(without quote), else y is “No”.Sample Input

2
3 3
1 2 1
2 1 2
1 2 1
3 3
1 2 3
2 1 2
3 2 1

Sample Output

Case #1: Yes
Case #2: No

Hint

first sample can be explained as below.

 #include<stdio.h>
#include<string.h>
using namespace std;
int n,m,g[][];
int f[][]= {{,},{,},{-,},{,-}};
bool dfs()
{
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
if(g[i][]==g[j][])
return true;
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
if(g[i][m]==g[j][m])
return true;
for(int i=; i<=m; i++)
for(int j=i+; j<=m; j++)
if(g[][i]==g[][j])
return true;
for(int i=; i<=m; i++)
for(int j=i+; j<=m; j++)
if(g[n][i]==g[n][j])
return true;
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
for(int k=; k<; k++)
{
int x=f[k][]+i,y=f[k][]+j;
if(g[i][j]==g[x][y])
return true;
}
}
}
return false;
}
int main()
{
int T;
scanf("%d",&T);
int t=;
while(T--)
//for(int t=1; t<=T; t++)
{
scanf("%d %d",&n,&m);
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
scanf("%d",&g[i][j]);
printf("Case #%d: ",t++);
if(dfs())
printf("Yes\n");
else
printf("No\n");
}
return ;
}

G - Left-handers, Right-handers and Ambidexters

You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.

The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.

Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.

Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

Input

The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

Output

Print a single even integer — the maximum number of
players in the team. It is possible that the team can only have zero
number of players.

Examples

Input
1 4 2
Output
6
Input
5 5 5
Output
14
Input
0 2 0
Output
0

Note

In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.

In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.

 #include<stdio.h>
int main()
{
int l,r,m;
scanf("%d%d%d",&l,&r,&m);
if(l==r)
{
if(m%==) printf("%d\n",l+r+m);
else printf("%d\n",l+r+m-);
}
else
{
if(l>r)
{
int temp=l;
l=r;
r=temp;
}
if(m<=r-l)
{
printf("%d\n",(m+l)*);
}
else
{
m=m-(r-l);
if(m&)
printf("%d\n",*r+m-);
else printf("%d\n",*r+m);
}
return ;
} }

I - Zebras

Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.

Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.

Input

In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.

Output

If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li
indices of days forming the subsequence. Indices must follow in
ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.

Subsequences may be printed in any order. If there are several
solutions, you may print any of them. You do not have to minimize nor
maximize the value of k.

Examples

Input
0010100
Output
3
3 1 3 4
3 2 5 6
1 7
Input
111
Output
-1
 #include<stdio.h>
#include<vector>
#include<string.h>
using namespace std; #define N 200100
int a[N];
char str[N];
int cnt;
int n,k;
vector <int> ans[N];
int main()
{
scanf("%s",str);
n=strlen(str);
for(int i=;i<n;i++)
{
a[i+]=str[i]-'';
}
cnt=;
for(int i=;i<=n;i++)
{
if(a[i]==) ans[cnt++].push_back(i);
else if(a[i]==)
{
if(cnt==)
{printf("-1\n");
return ;}
ans[--cnt].push_back(i);
}
k=max(k,cnt);
}
if(k!=cnt)printf("-1\n");
else
{
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
{
printf("%d",ans[i].size());
for(int j=;j<ans[i].size();j++)
{
printf(" %d",ans[i][j]);
}
printf("\n");
}
}
return ;
}

多校练习赛3

Problem D. Euler Function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1340    Accepted Submission(s): 1008

Problem Description
In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n that are relatively prime to n. It can be defined more formally as the number of integers k in the range 1≤k≤n for which the greatest common divisor gcd(n,k) is equal to 1.
For example, φ(9)=6 because 1,2,4,5,7 and 8 are coprime with 9. As another example, φ(1)=1 since for n=1 the only integer in the range from 1 to n is 1 itself, and gcd(1,1)=1.
A
composite number is a positive integer that can be formed by
multiplying together two smaller positive integers. Equivalently, it is a
positive integer that has at least one divisor other than 1 and itself. So obviously 1 and all prime numbers are not composite number.
In this problem, given integer k, your task is to find the k-th smallest positive integer n, that φ(n) is a composite number.
 
Input
The first line of the input contains an integer T(1≤T≤100000), denoting the number of test cases.
In each test case, there is only one integer k(1≤k≤109).
 
Output
For each test case, print a single line containing an integer, denoting the answer.
 
Sample Input
2
1
2
 
Sample Output
5
7
 #include<stdio.h>
int main()
{
int t;
long long k;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&k);
if(k==) printf("5\n");
else
{
printf("%lld\n",k+);
}
}
return ;
}

Problem F. Grab The Tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1581    Accepted Submission(s): 762

Problem Description
Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2,...,n, connected by n−1 bidirectional edges. The i-th vertex has the value of wi.
In
this game, Little Q needs to grab some vertices on the tree. He can
select any number of vertices to grab, but he is not allowed to grab
both vertices that are adjacent on the tree. That is, if there is an
edge between x and y, he can't grab both x and y.
After Q's move, Little T will grab all of the rest vertices. So when
the game finishes, every vertex will be occupied by either Q or T.
The
final score of each player is the bitwise XOR sum of his choosen
vertices' value. The one who has the higher score will win the game. It
is also possible for the game to end in a draw. Assume they all will
play optimally, please write a program to predict the result.
 
Input
The first line of the input contains an integer T(1≤T≤20), denoting the number of test cases.
In each test case, there is one integer n(1≤n≤100000) in the first line, denoting the number of vertices.
In the next line, there are n integers w1,w2,...,wn(1≤wi≤109), denoting the value of each vertex.
For the next n−1 lines, each line contains two integers u and v, denoting a bidirectional edge between vertex u and v.
 
Output
For
each test case, print a single line containing a word, denoting the
result. If Q wins, please print Q. If T wins, please print T. And if the
game ends in a draw, please print D.
 
Sample Input
1
3
2 2 2
1 2
1 3
 
Sample Output
Q
 #include<stdio.h>
int main()
{
int t,n,a,b;
int aq[];
scanf("%d",&t); while(t--)
{
int ans=;
scanf("%d",&n); for(int i=; i<n; i++)
{
scanf("%d",&aq[i]);
ans=ans^aq[i]; }
for(int i=; i<n-; i++)
{
scanf("%d %d",&a,&b);
}
if(ans==)
printf("D\n");
else printf("Q\n"); }
return ;
}

预定义

 #include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <string>
#include <iostream> using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", (n))
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mm(a,n) memset(a, n, sizeof(a))
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f; //head

Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.

Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.

You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.

The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.

It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Output

Print the maximum number of files the intercepted array could consist of.

Examples

Input
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
Output
3
Input
3 3
1 10 100
1 100 10
Output
2
Input
1 4
4
1 1 1 1
Output
1

Note

In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.

In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.

In the third example the only possibility is that the archive contains a single file of size 4.

 #include<stdio.h>
int a[];
int b[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int i=; i<=m; i++)
{
scanf("%d",&b[i]);
}
int i=,j=;
int sum=;
int sum1=a[];
int sum2=b[];
while(i<=n &&j<=m)
{
if(sum1>sum2)
{
j++;
sum2+=b[j];
}
else if(sum1<sum2)
{
i++;
sum1+=a[i];
}
else
{
sum++;
i++;
j++;
if(i<=n &&j<=m)
{
sum1=a[i];
sum2=b[j];
} } }
printf("%d\n",sum);
}

ACM 第七天的更多相关文章

  1. 【优质blog、网址】置顶

    一.大公司等技术blog:   blog1: http://blog.csdn.net/mfcing/article/details/51577173 blog2: http://blog.csdn. ...

  2. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  3. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  4. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  5. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

  6. 山东省第七届ACM省赛------Fibonacci

    Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...

  7. 山东省第七届ACM省赛------Julyed

    Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...

  8. ZZUOJ-1195-OS Job Scheduling(郑州大学第七届ACM大学生程序设计竞赛E题)

    1195: OS Job Scheduling Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 106  Solved: 35 [id=1195&quo ...

  9. 第七届山东省ACM省赛

    激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...

随机推荐

  1. iOS 清理Xcode项目中没有使用到的图片资源和类文件

    接手到一个旧的项目,但是发现里面有太多的无用资源,包括升级app后,一些无用的图片资源并没有被删掉,导致app在打包成ipa包以后,文件变大.手边这个项目IM要更换成环信的IM,之前的一些旧的SDK, ...

  2. Git 原理入门

    Git 是最流行的版本管理工具,也是程序员的必备技能之一. 即使天天使用它,很多人也未必了解它的原理.Git 为什么可以管理版本?git add.git commit这些基本命令,到底在做什么,你说得 ...

  3. PHP获取当月天数,获取当月的每天的开始和结束的时间戳,获取当月每号

    由于经常要写导单和数据分析功能,所以要获取什么时间的数据,想什么当天,周,年,月之类的时间格式都很好获取.我今天在这里为大家提供的是当月每天的开始和结束的时间格式. 希望能帮到大家!!! # 获取当月 ...

  4. 【篇一】Python安装与初识

    一.python3.6安装 windows: 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python27 3.配置环境变量 [右 ...

  5. python爬虫#数据存储#JSON/CSV/MYSQL/MongoDB/

    Json数据处理 JSON支持数据格式: 对象(字典).使用花括号. 数组(列表).使用方括号. 整形.浮点型.布尔类型还有null类型. 字符串类型(字符串必须要用双引号,不能用单引号). 多个数据 ...

  6. python学习——复习

    一.基础知识: 1.文件操作有哪些模式?请简述各模式的作用. 'r' 读模式,相应的方法有 read(),readline(),readlines() 'w' 写模式,相应的方法有 write(),w ...

  7. SaltStack error: No module named 'salt'

    启动saltstack的时候出现下面的错误 问题原因 是因为我在centos7中安装了多版本的python导致的 解决方案 将文件下面文件首行更改成python2 [root@saltstack-12 ...

  8. 中国大学MOOC-C程序设计(浙大翁恺)—— 时间换算

    时间换算(10分) 题目内容: UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8.现在,你的程序要读入一个整数,表示BJT的时和分.整数的个位和十位表示分,百位和千位表示小时.如果小 ...

  9. 20145202马超《网络对抗》Exp5MSF基础应用

    20145202马超<网络对抗>Exp5MSF基础应用 本实践目标,掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路.具体需要完成(1)一个主动攻击,如ms08_067 ...

  10. 20145234黄斐《Java程序设计》第八周学习总结

    教材学习内容总结 第十五章部分 - 通用API 通用API 日志: 日志对信息安全意义重大,审计.取证.入侵检测等都会用到日志信息 日志API Logger: 注意无法使用构造方法生成Logger对象 ...