Automatic Judge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 827 Accepted Submission(s): 284
A new automatic judge system is used for this competition. During the five-hour contest time, you can submit your code to the system, then the judge will reply you. Here is a list of the judge's replies and their meaning:
1. Accepted(AC): Yes, your program is correct. You did a good job!
2. PresentationError(PE) : Your program's output format is not exactly the same as required by the problem, although the output is correct. This usually means the existence of omitted or extra blank characters (white spaces, tab characters and/or new line characters) between any two non-blank characters, and/or blank lines (a line consisting of only blank characters) between any two non-blank lines. Trailing blank characters at the end of each line and trailing blank lines at the of output are not considered format errors. Check the output for spaces, blank lines, etc. against the problem's output specification.
3. WrongAnswer(WA) : Correct solution not reached for the inputs. The inputs and outputs that we use to test the programs are not public (it is recomendable to get accustomed to a true contest dynamic :-)
4. RuntimeError(RE) : Your program failed during the execution and you will receive the hints for the reasons.
5. TimeLimitExceeded(TLE) : Your program tried to run during too much time.
6. MemoryLimitExceeded(MLE): Your program tried to use more memory than the judge default settings.
7. OutputLimitExceeded(OLE): Your program tried to write too much information. This usually occurs if it goes into a infinite loop.
8. CompilationError(CE): The compiler fails to compile your program. Warning messages are not considered errors. Click on the judge's reply to see the warning and error messages produced by the compiler.
For each submission, if it is the first time that the judge returns ``AC'' on this problem, then it means you have passed this problem, and the current time will be added to the penalty of your team. In addition, every time you pass a problem, each unsuccessful try for that problem before is counted as 20 minutes penalty, it should also be added to the penalty of your team.
Now given the number of problems in the contest and the submission records of a team. Please write a program to calculate the number of problems the team passed and their penalty.
In each test case, there are two integers n(1≤n≤13) and m(1≤m≤100) in the first line, denoting the number of problems and the number of submissions of a team. Problems are labeled by 1001, 1002, ..., 1000+n.
In the following m lines, each line contains an integer x(1001≤x≤1000+n) and two strings t(00:00≤t≤05:00) and s, denoting the team submits problem xat time t, and the result is s. t is in the format of HH:MM, while s is in the set \{AC, PE, WA, RE, TLE, MLE, OLE\}. The team is so cautious that they never submit a CE code. It is guaranteed that all the t in the input is in ascending order and every t is unique.
第一题水题:坑点在如果这道题一直WA,没有AC的话是不加罚时的,Orz,我这里开一个WA次数的数组,一个标记数组,如果这个题一直没A为0状态,就减去次数*WA的时间。
#include <bits/stdc++.h>
using namespace std;
int flag[1050];
int flag2[1050];
int c[1050];
string id;
//int a[1050][];
int main()
{
// freopen("in.txt","r",stdin);
int sum;
int sum1;
int T;
scanf("%d",&T);
while(T--)
{
int num;
memset(flag,0,sizeof(flag));
memset(c,0,sizeof(c));
sum = 0;
sum1 = 0;
int n,m;
int cnt = 0;
scanf("%d%d",&n,&m);
while(m--)
{
int h,mi;
char res[50];
scanf("%d %d:%d %s",&num,&h,&mi,res);
int time = mi+h*60;
if(!flag[num]&&res[0]=='A'&&res[1]=='C')
{
sum += time;
flag[num] = 1;
cnt++;
}
else if(!flag[num]) {
sum += 20;
c[num]++;
}
if(cnt == n)
break;
}
for(int i = 1001; i <= 1013; i++) {
if(!flag[i])
sum -= (c[i]*20);
}
printf("%d %d\n",cnt,sum);
}
return 0;
}
Easy Summation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 801 Accepted Submission(s): 294
Given two integers n and k. Let f(i)=ik, please evaluate the sum f(1)+f(2)+...+f(n). The problem is simple as it looks, apart from the value of n in this question is quite large.
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7.
Each of the following T lines contains two integers n(1≤n≤10000) and k(0≤k≤5).
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000000+7;
ll mypow(ll n,int k)
{
ll ret=1;
while(k--)
ret=ret*n%mod;
return ret;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,k;
scanf("%d%d",&n,&k);
ll ans=0;
for(int i=1;i<=n;i++)
{
ans=(ans+mypow(i,k))%mod;
}
printf("%I64d\n",ans);
}
return 0;
}
Building Shops
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 419 Accepted Submission(s): 103
The total cost consists of two parts. Building a candy shop at classroom i would have some cost ci. For every classroom P without any candy shop, then the distance between P and the rightmost classroom with a candy shop on P's left side would be included in the cost too. Obviously, if there is a classroom without any candy shop, there must be a candy shop on its left side.
Now Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.
In each test case, the first line contains an integer n(1≤n≤3000), denoting the number of the classrooms.
In the following n lines, each line contains two integers xi,ci(−109≤xi,ci≤109), denoting the coordinate of the i-th classroom and the cost of building a candy shop in it.
There are no two classrooms having same coordinate.
1002 Building Shops http://acm.hdu.edu.cn/showproblem.php?pid=6024
这题题目有点难看懂;
题意: x轴上有n个班级,第i个班级建商店的费用为c[i];不建的话也会有费用,费用就是从i到距离i的左边最近的商店的距离,问总费用最少是多少;
题解:毫无疑问,第1个教室是肯定要建商店的;
然后就dp; dp[I][0]表示第I个教室不建商店,前I个教师的花费;
dp[I][1]表示第I个教室建商店,前I个教师的花费;
状态转移的话 dp[I][1] = min(dp[I-1][0], dp[I-1][1]) + c[I];
dp[I][0] 的转移有点坑我一开始以为是由dp[I-1][0]转来的,然后贡献了一次wa;
是这样的,dp[I][0] = dp[j][0] + x[I]-x[j]; (j=1~I-1);
代码:
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- const int MAXN = 3008;
- ll dp[MAXN][2];
- //int path[MAXN];
- struct classroom {
- int x, c;
- } ritian[MAXN];
- int cmp(classroom xx, classroom yy) {
- return xx.x < yy.x;
- }
- int main() {
- int n;
- //freopen("in.txt", "r", stdin);
- while (~scanf("%d", &n)) {
- for(int i = 1; i <= n; i++)
- scanf("%d%d", &ritian[i].x, &ritian[i].c);
- sort(ritian+1, ritian+n+1, cmp);
- dp[1][0] = (ll)1<<60;
- dp[1][1] = ritian[1].c;
- for(int i = 2; i <= n; i++) {
- dp[i][1] = min(dp[i-1][0], dp[i-1][1])+ritian[i].c;
- ll tmp = 0;
- dp[i][0] = (ll)1<<60;
- for(int j = i-1; j > 0; j--) {
- tmp = (ll)(ritian[j+1].x-ritian[j].x)*(i-j)+tmp;//这里少写了(ll)也贡献了2次wa,强迫症的我表示一个变量的值小于int型,我决不 //会定义成long long 型->.->;
- dp[i][0] = min(dp[i][0], dp[j][1]+tmp);
- }
- }
- printf("%I64d\n", min(dp[n][0], dp[n][1]));
- }
- return 0;
- }
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- const int N=3;
- typedef long long ll;
- const ll Mod=1000000000+7;
- struct Mat
- {
- ll mat[N+1][N+1];
- };
- Mat Multiply(Mat a, Mat b)
- {
- Mat c;
- memset(c.mat, 0, sizeof(c.mat));
- for(int k = 0; k < N; ++k)
- for(int i = 0; i < N; ++i)
- if(a.mat[i][k])
- for(int j = 0; j < N; ++j)
- if(b.mat[k][j])
- c.mat[i][j] = (c.mat[i][j] +a.mat[i][k] * b.mat[k][j])%Mod;
- return c;
- }
- Mat QuickPower(Mat a, ll k)
- {
- Mat c;
- memset(c.mat,0,sizeof(c.mat));
- for(int i = 0; i < N; ++i)
- c.mat[i][i]=1;
- for(; k; k >>= 1)
- {
- if(k&1) c = Multiply(c,a);
- a = Multiply(a,a);
- }
- return c;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- ll a[]={0,1,3,4,6};
- Mat A;
- A.mat[0][0]=1,A.mat[0][1]=1,A.mat[0][2]=0;
- A.mat[1][0]=0,A.mat[1][1]=0,A.mat[1][2]=1;
- A.mat[2][0]=1,A.mat[2][1]=0,A.mat[2][2]=0;
- while(T--)
- {
- ll n;
- scanf("%I64d",&n);
- if(n<=4)
- {
- printf("%I64d\n",a[n]);
- continue;
- }
- Mat ans=QuickPower(A,n-4);
- printf("%I64d\n",(a[4]*ans.mat[0][0]+a[3]*ans.mat[1][0]+a[2]*ans.mat[2][0])%Mod);
- }
- return 0;
- }
Coprime Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 545 Accepted Submission(s): 190
``Coprime Sequence'' is easy to find because of its restriction. But we can try to maximize the GCD of these integers by removing exactly one integer. Now given a sequence, please maximize the GCD of its elements.
In each test case, there is an integer n(3≤n≤100000) in the first line, denoting the number of integers in the sequence.
Then the following line consists of n integers a1,a2,...,an(1≤ai≤109), denoting the elements in the sequence.
前缀后缀gcd
去掉一个元素能使这个数列的GCD最大为多少
分析:
我们求一个数列的GCD,是先求前两个元素的GCD,然后将这个GCD值在与下一个元素进行GCD运算。由此可知进行GCD运算的顺序对最终的结果是没有影响的。我们再看看数列的长度范围,小于100000。那我们就枚举去掉的那个元素,那么去掉元素后的数列的GCD即这个元素前面一段数列的GCD再与这个元素后面一段数列的GCD进行GCD运算。所以我们需要两个数组分别记录前缀GCD和后缀GCD,这两个数组都可以通过O(n)算法算出来。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000+5];
int pre[100000+5],suf[100000+5];
int gcd(int a, int b)
{
while(b)
{
int c = a%b;
a = b;
b = c;
}
return a;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d",&a[i]);
pre[0]=a[0];
for(int i=1; i<n; i++)
{
pre[i]=gcd(pre[i-1],a[i]);
}
suf[n-1]=a[n-1];
for(int i=n-2; i>=0; i--)
{
suf[i]=gcd(suf[i+1],a[i]);
}
int ans=max(suf[1],pre[n-2]);
for(int i=1;i<n-1;i++)
{
ans=max(ans,gcd(pre[i-1],suf[i+1]));
}
printf("%d\n",ans);
}
return 0;
}
Graph Theory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 466 Accepted Submission(s): 136
Let the set of vertices be {1, 2, 3, ..., n}. You have to consider every vertice from left to right (i.e. from vertice 2 to n). At vertice i, you must make one of the following two decisions:
(1) Add edges between this vertex and all the previous vertices (i.e. from vertex 1 to i−1).
(2) Not add any edge between this vertex and any of the previous vertices.
In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices. A perfect matching is a matching that each vertice is covered by an edge in the set.
Now Little Q is interested in checking whether a ''Cool Graph'' has perfect matching. Please write a program to help him.
In each test case, there is an integer n(2≤n≤100000) in the first line, denoting the number of vertices of the graph.
The following line contains n−1 integers a2,a3,...,an(1≤ai≤2), denoting the decision on each vertice.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int MAXN = 100008;
int a[MAXN];
int main() {
int n, T;
//freopen("in.txt", "r", stdin);
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for(int i = 1; i < n; i++)
scanf("%d", &a[i]);
if (n%2) {
printf("No\n");
continue;
}
int p = 0;
a[0] = 2;
for(int i = n-1; i >= 0; i--) {
if (a[i] == 1)
p++;
else p--;
if (p < 0) break;
}
if (p < 0) printf("No\n");
else printf("Yes\n");
}
return 0;
}