2016CCPC东北赛补题
A - Minimum’s Revenge HDU - 5922
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?
Input
The 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.
Output
For 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
题意
给你一棵树,有n个节点,编号从1~n,每两个节点之间都有一条边权值为两个节点编号的最小公倍数。问最小生成树的权值和为多少?
分析
所有都和1相连 形成一个花QAQ...
坑
用long long;
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
long long n;
int cas = 1;
cin>>T;
while(T--)
{
cin>>n;
printf("Case #%d: %lld\n",cas++,(n+2)*(n-1)/2);
}
return 0;
}
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 A/B+B/A≤C/D+D/C
Input
first 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).
Output
For 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
int main()
{
int T;
cin>>T;
int cas=1;
while(T--)
{
cin>>a>>b;
printf("Case #%d:\n",cas++);
if(a==b)
{
cout<<1<<endl;
cout<<a<<' '<<b<<endl;
}
else
{
cout<<2<<endl;
cout<<a<<' '<<b<<endl;
cout<<b<<' '<<a<<endl;
}
}
return 0;
}
Mr. Frog’s Game
题太长了不贴了 ,连连看
直接莽就行了 数据这么小
但是 自己因为全局变量覆盖部分变量... ...
还有CAse 哇了好多发 真难受
#include <bits/stdc++.h>
using namespace std;
const int maxn=33;
int mp[maxn][maxn];
int meo[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
int n,m;
bool check()
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(i==j) continue;
if(mp[i][m]==mp[j][m])
return true;
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(i==j) continue;
if(mp[i][1]==mp[j][1])
return true;
}
}
for(int i=1; i<=m; i++)
{
for(int j=1; j<=m; j++)
{
if(i==j) continue;
if(mp[n][i]==mp[n][j])
return true;
}
}
for(int i=1; i<=m; i++)
{
for(int j=1; j<=m; j++)
{
if(i==j) continue;
if(mp[1][i]==mp[1][j])
return true;
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
for(int t=0; t<4; t++)
{
int x=i+meo[t][0];
int y=j+meo[t][1];
if(mp[x][y]==mp[i][j])
return true;
}
}
}
return false;
}
int main()
{
int t;
cin>>t;
int cas=1;
while(t--)
{
// int n,m;
cin>>n>>m;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cin>>mp[i][j];
}
}
//cas=1;
//cout<<"Case #"<<cas++<<':'<<' ';
printf("Case #%d: ",cas++);
if(check())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
Basic Data Structure
Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack:
∙ PUSH x: put x on the top of the stack, x must be 0 or 1.
∙ POP: throw the element which is on the top of the stack.
Since it is too simple for Mr. Frog, a famous mathematician who can prove "Five points coexist with a circle" easily, he comes up with some exciting operations:
∙REVERSE: Just reverse the stack, the bottom element becomes the top element of the stack, and the element just above the bottom element becomes the element just below the top elements... and so on.
∙QUERY: Print the value which is obtained with such way: Take the element from top to bottom, then do NAND operation one by one from left to right, i.e. If atop,atop−1,⋯,a1 is corresponding to the element of the Stack from top to the bottom, value=atop nand atop−1 nand ... nand a1. Note that the Stack will not change after QUERY operation. Specially, if the Stack is empty now,you need to print ” Invalid.”(without quotes).
By the way, NAND is a basic binary operation:
∙ 0 nand 0 = 1
∙ 0 nand 1 = 1
∙ 1 nand 0 = 1
∙ 1 nand 1 = 0
Because Mr. Frog needs to do some tiny contributions now, you should help him finish this data structure: print the answer to each QUERY, or tell him that is invalid.
Input
The first line contains only one integer T (T≤20), which indicates the number of test cases.
For each test case, the first line contains only one integers N (2≤N≤200000), indicating the number of operations.
In the following N lines, the i-th line contains one of these operations below:
∙ PUSH x (x must be 0 or 1)
∙ POP
∙ REVERSE
∙ QUERY
It is guaranteed that the current stack will not be empty while doing POP operation.
Output
For each test case, first output one line "Case #x:w, where x is the case number (starting from 1). Then several lines follow, i-th line contains an integer indicating the answer to the i-th QUERY operation. Specially, if the i-th QUERY is invalid, just print " Invalid."(without quotes). (Please see the sample for more details.)
Sample Input
2
8
PUSH 1
QUERY
PUSH 0
REVERSE
QUERY
POP
POP
QUERY
3
PUSH 0
REVERSE
QUERY
Sample Output
Case #1:
1
1
Invalid.
Case #2:
0
Hint
In the first sample: during the first query, the stack contains only one element 1, so the answer is 1. then in the second query, the stack contains 0, l
(from bottom to top), so the answer to the second is also 1. In the third query, there is no element in the stack, so you should output Invalid.
分析
显而易见的遇到0就会置1
注意特判 0前面没有数的时候
用优先队列简单模拟一下
cur==1的时候当时没有考虑到应该pop 还是塞进去了个cur-1
cin输入会超时
#include <bits/stdc++.h>
using namespace std;
deque<int>dq;
//string s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
bool flag=true;
int T;
cin>>T;
int cas=1;
while(T--)
{
dq.clear();
int n;
cin>>n;
cout<<"Case #"<<cas++<<":\n";
// printf("Case #%d:\n", cas++);
for(int i=0; i<n; i++)
{
string s;
cin>>s;
if(s[2]=='S')
{
int x;
cin>>x;
if(dq.empty())
dq.push_back(x);
else if(x==0)
{
if (flag)
dq.push_front(x);
else
dq.push_back(x);
}
else if(x==1)
{
if(flag)
{
int cur=dq.front();
if(cur==0)
dq.push_front(x);
else
{
dq.pop_front();
cur++;
dq.push_front(cur);
}
}
else
{
int cur=dq.back();
if(cur==0)
dq.push_back(x);
else
{
dq.pop_back();
cur++;
dq.push_back(cur);
}
}
}
}
else if(s[2]=='P')
{
if(flag)
{
int cur=dq.front();
if(cur==0||cur==1)
dq.pop_front();
else
{
dq.pop_front();
cur--;
dq.push_front(cur);
}
}
else
{
int cur=dq.back();
if(cur==0||cur==1)
dq.pop_back();
else
{
dq.pop_back();
cur--;
dq.push_back(cur);
}
}
}
else if(s[2]=='V')
flag=!flag;
else if(s[2]=='E')
{
int cur;
if(dq.empty())
{
cout<<"Invalid."<<endl;
continue;
}
else if(flag)
cur=dq.back();
else
cur=dq.front();
if(dq.size() == 1)
{
if(cur == 0) cout<<0<<endl;
else if(cur%2) cout<<1<<endl;
else cout<<0<<endl;
}
else if(dq.size() == 2)
{
if(cur==0) cout<<1<<endl;
else if(cur%2) cout<<1<<endl;
else cout<<0<<endl;
}
else
{
if(cur==0)cout<<1<<endl;
else if(cur%2) cout<<0<<endl;
else cout<<1<<endl;
}
}
}
}
return 0;
}
剩下的题我以后一定会补完的
有两道应该能不出来了
今天是因为要踢球啊喵...