水题

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. PHP 中根据 IP 获取地址

    这里使用的是淘宝 IP 地址库提供的 API 接口. 淘宝 IP 地址库:http://ip.taobao.com/instructions.html API 文档说明:  使用事例: /** * 调 ...

  2. Spring Security学习笔记(三)

    之前提到过认证后怎么存放用户信息,令牌token是一种方式,session是另一种方式,这里介绍使用spring session data redis存储httpSession. 添加了以上依赖后,我 ...

  3. windows简易使用composer 安装国内镜像

    1.下载composer.phar文件 地址: https://getcomposer.org/download/  从下面选择一个 2.下载成功,新建项目(找到已有的项目文件夹)文件夹(D:\PHP ...

  4. 第七篇:gcc和arm-linux-gcc常用选项

    目录 一.gcc和arm-linux-gcc的常用选项 二.从.c文件到可执行文件过程 一.gcc和arm-linux-gcc的常用选项 常用选型 -v 查看gcc编译器的版本,显示gcc执行时的详细 ...

  5. inotify和epoll

    参考EventHub.cpp 1.初始化inotify int mINotifyFd = inotify_init(); 2.将要监测的目录添加到inotify int result = inotif ...

  6. Python学习:8.小项目之登录注册验证

    简介 本次项目登录注册验证是对之前学习知识点的加深学习,这次项目的练习的知识点有函数.判断语句.循环语句.文件操作等. 项目流程 运行代码之后,输出登录或者注册选项. 当选择登录之后,输入用户名密码, ...

  7. C语言实现''student a am i''字符串的正确排列

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int Reverse(char a[ ...

  8. linux mint系统 cinnamon桌面 发大镜功能

    让我来告诉迷途中的你cinnamon桌面一个好用的功能. 选择设置 选择窗口 -> 选择行为 看那个窗口移动和调整大小的特殊键 Alt 好了按住alt在滑动滑轮 世界不一样了 对于小屏幕高分辨率 ...

  9. 模仿淘宝首页写的高仿页面,脚本全用的原生JS,菜鸟一枚高手看了勿喷哈

    自己仿照淘宝首页写的页面,仿真度自己感觉可以.JS脚本全是用原生JavaScript写得,没用框架.高手看了勿喷,请多多指正哈!先上网页截图看看效果,然后上源码: 上源码,先JavaScript : ...

  10. [Python3.x]多次登陆锁定用户

    要求:输入用户名,密码认证成功显示欢迎信息输入错误三次后锁定用户Readme: 1.account.txt是存放用户id及密码的文件 2.account_loc.txt是存放被锁定的用户id的文档,默 ...