ACM 第七天
水题
B - Minimum’s Revenge
Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
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
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.
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.
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
1 4 2
6
5 5 5
14
0 2 0
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.
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
0010100
3
3 1 3 4
3 2 5 6
1 7
111
-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
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.
In each test case, there is only one integer k(1≤k≤109).
1
2
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
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.
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.
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.
3
2 2 2
1 2
1 3
#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.
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
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
3
3 3
1 10 100
1 100 10
2
1 4
4
1 1 1 1
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 第七天的更多相关文章
- 【优质blog、网址】置顶
一.大公司等技术blog: blog1: http://blog.csdn.net/mfcing/article/details/51577173 blog2: http://blog.csdn. ...
- 山东省第七届ACM省赛------Memory Leak
Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...
- 山东省第七届ACM省赛------Reversed Words
Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- 山东省第七届ACM省赛------The Binding of Isaac
The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...
- 山东省第七届ACM省赛------Fibonacci
Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...
- 山东省第七届ACM省赛------Julyed
Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...
- 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 ...
- 第七届山东省ACM省赛
激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...
随机推荐
- 常用EL函数汇总 fn:contains ,fn:substring,fn:substringAfter...
由于在JSP页面中显示数据时,经常需要对显示的字符串进行处理,SUN公司针对于一些常见处理定义了一套EL函数库供开发者使用.这些EL函数在JSTL开发包中进行描述,因此在JSP页面中使用SUN公司的E ...
- obfuscator-llvm Xcode集成配置
一.简介 obfuscator-llvm 是一个开源的代码混淆编译器,能够使编译出来的文件添加垃圾代码和各种跳转流程,给逆向分析者增加难度. 二.编译 (1) 下载 目前最新版的是4.0的,下载地址是 ...
- axios和ajax,fetch的区别
1,传统 Ajax 指的是 XMLHttpRequest(XHR), 最早出现的发送后端请求技术,隶属于原始js中,核心使用XMLHttpRequest对象,多个请求之间如果有先后关系的话,就会出现回 ...
- WEB中需求分析应该考虑的问题
一. 针对用户群体要考虑因素 1.用户年龄 2.选择素材 3.网站布局 4.颜色搭配 5. 用户体验及动效 6.功能便捷 用户需求.用户兴趣爱好.性格.职业.教育水平高低.消费观念.PC端和移动端哪一 ...
- hadoop生态搭建(3节点)-15.Nginx_Keepalived_Tomcat配置
# Nginx+Tomcat搭建高可用服务器名称 预装软件 IP地址Nginx服务器 Nginx1 192.168.6.131Nginx服务器 Nginx2 192.168.6.132 # ===== ...
- Final,finally,finalize区别
final— 修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能既被声明为 abstract的,又被声明为final的.将变量或方法声明为f ...
- 第2天 Java基础语法
第2天 Java基础语法 今日内容介绍 变量 运算符 变量 变量概述 前面我们已经学习了常量,接下来我们要学习变量.在Java中变量的应用比常量的应用要多很多.所以变量也是尤为重要的知识点! 什么是变 ...
- LeetCode初级算法的Python实现--链表
LeetCode初级算法的Python实现--链表 之前没有接触过Python编写的链表,所以这里记录一下思路.这里前面的代码是和leetcode中的一样,因为做题需要调用,所以下面会给出. 首先定义 ...
- 安装cuda9.0+cudnn v7+python3.5.3+tensorflow
本机设备 windows10 gtx1060 安装软件及下载地址 python-3.5.3-amd64 链接:https://pan.baidu.com/s/1I3oIDatMgvDLEtaPtvu ...
- 从国内下载Linux的CentOS系统
http://mirror.nsc.liu.se/centos-store/7.3.1611/isos/x86_64/