A water problem
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Two planets named Haha and Xixi in the universe and they were created with the universe beginning.
There is 73 days in Xixi a year and 137 days in Haha a year.
Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.
There is 73 days in Xixi a year and 137 days in Haha a year.
Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.
Input
There are several test cases(about
5 huge test cases).
For each test, we have a line with an only integer N(0≤N), the length of N is up to 10000000.
For each test, we have a line with an only integer N(0≤N), the length of N is up to 10000000.
Output
For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.
Sample Input
10001 0 333
Sample Output
Case #1: YES Case #2: YES Case #3: NO
思路:大数取模,直接套模板
#include<stdio.h>
#include <map>
#include<cmath>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
char a[10000055];
long long modNumber(char * s,int modNumber);
int main()
{
long long t = 0;
int b = 10001;
while(scanf("%s",&a) != EOF)
{
t++;
long long re = modNumber(a,b);
if(re == 0)
{
printf("Case #%d: YES\n",t);
continue;
}
else
{
printf("Case #%d: NO\n",t);
continue;
}
memset(a,0,sizeof(a));
}
return 0;
}
long long modNumber(char * s,int modNumber)
{
long long sum = 0;
for (int i = 0; i < strlen(s); ++i)
{
sum = sum*10 + s[i]-48;//每个位取模
sum %= modNumber;
}
return sum;
}
Zhu and 772002
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.
Input
First line is a positive integer
T , represents there are
T test cases.
For each test case:
First line includes a number n(1≤n≤300),next line there are n numbers a1,a2,...,an,(1≤ai≤1018).
For each test case:
First line includes a number n(1≤n≤300),next line there are n numbers a1,a2,...,an,(1≤ai≤1018).
Output
For the i-th test case , first output Case #i: in a single line.
Then output the answer of i-th test case modulo by 1000000007.
Then output the answer of i-th test case modulo by 1000000007.
Sample Input
2 3 3 3 4 3 2 2 2
Sample Output
Case #1: 3 Case #2: 3
思路:
高斯消元(异或方程组)和 快速幂求模
#include <stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;
#define maxL (2000>>5)+1
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5] |= 1<<(x&31))
#define MOD 1000000007
//快速幂求和
long long PowerMod(long long a, long long b, long long c)
{
long long ans = 1;
a = a % c;
while(b>0)
{
if(b % 2 == 1)
ans = (ans * a) % c;
b = b/2;
a = (a * a) % c;
}
return ans;
}
long long mark[maxL];
long long P[2005], Pt = 0;
long long f[2005][2005];
void sieve()
{
register int i, j, k;
SET(1);
int n = 2000;
for(i = 2; i <= n; i++) {
if(!GET(i)) {
for(k = n/i, j = i*k; k >= i; k--, j -= i)
SET(j);
P[Pt++] = i;
}
}
}
int main()
{
int T;
sieve();
int testcase, n;
scanf("%d", &T);
for(int k=1;k<=T;k++)
{
scanf("%d", &n);
memset(f,0,sizeof(f));
long long x;
for(int i = 0; i < n; i++)
{
scanf("%lld", &x);
for(int j = 0; j < Pt; j++)
while(x%P[j] == 0)
x /= P[j], f[j][i] ^= 1;
}
// xor gauss
long long row = Pt, col = n, arb = 0;
for(int r = 0, c = 0; r < row && c < col; c++)
{
int k = r;
for(int j = r + 1; j < row; j++)
if(f[j][c]) k = j;
for(int j = 0; j < col; j++)
swap(f[r][j], f[k][j]);
if(f[r][c] == 0)
{
arb++;
continue;
}
for(int j = 0; j < row; j++)
{
if(r == j) continue;
if(f[j][c])
{
for(int k = col; k >= c; k--)
f[j][k] = f[j][k] ^ f[r][k];
}
}
r++;
}
long long re1= PowerMod(2,arb,MOD);//结果为极大的幂,所以对其取模
printf("Case #%d:\n",k);
printf("%lld\n",re1 - 1 );
}
return 0;
}
Danganronpa
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of
n kinds with
a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students' desks are in a row. Chiaki Nanami wants to arrange gifts like this:
1. Each table will be prepared for a mysterious gift and an ordinary gift.
2. In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.
3. There are no limits for the mysterious gift.
4. The gift must be placed continuously.
She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren't you?
1. Each table will be prepared for a mysterious gift and an ordinary gift.
2. In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.
3. There are no limits for the mysterious gift.
4. The gift must be placed continuously.
She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren't you?
Input
The first line of input contains an integer
T(T≤10) indicating the number of test cases.
Each case contains one integer n. The next line contains n (1≤n≤10) numbers: a1,a2,...,an, (1≤ai≤100000).
Each case contains one integer n. The next line contains n (1≤n≤10) numbers: a1,a2,...,an, (1≤ai≤100000).
Output
For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami's question.
Sample Input
1 2 3 2
Sample Output
Case #1: 2
#include<stdio.h>
#include <map>
#include<cmath>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
long long a[30];
int main()
{
int T,n;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
long long re = 0;
long long sum =0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
sum += a[i];
}
sort(a+1,a+n);//排序
for(int i=1;i<=n;i++)
{
for(int j=1 ;j<=a[i] ;j++)
{
if(!(sum - re >=re+2)) break;//礼物不够跳出
re ++;
a[i+1]--;
}
}
printf("Case #%d: %lld\n",k,re);
}
return 0;
}
Lweb and String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Lweb has a string
S.
Oneday, he decided to transform this string to a new sequence.
You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing).
You need transform every letter in this string to a new number.
A is the set of letters of S, B is the set of natural numbers.
Every injection f:A→B can be treat as an legal transformation.
For example, a String “aabc”, A={a,b,c}, and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3.
Now help Lweb, find the longest LIS which you can obtain from S.
LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
Oneday, he decided to transform this string to a new sequence.
You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing).
You need transform every letter in this string to a new number.
A is the set of letters of S, B is the set of natural numbers.
Every injection f:A→B can be treat as an legal transformation.
For example, a String “aabc”, A={a,b,c}, and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3.
Now help Lweb, find the longest LIS which you can obtain from S.
LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)
Input
The first line of the input contains the only integer
T,(1≤T≤20).
Then T lines follow, the i-th line contains a string S only containing the lowercase letters, the length of S will not exceed 105.
Then T lines follow, the i-th line contains a string S only containing the lowercase letters, the length of S will not exceed 105.
Output
For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.
Sample Input
2 aabcc acdeaa
Sample Output
Case #1: 3 Case #2: 4
思路很简单,统计一共有几个不同字母就好:
#include<stdio.h>
#include <map>
#include<cmath>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
char s[100005];
long long a[30];
int main()
{
int T;
scanf("%d",&T);
memset(s,0,sizeof(s));
memset(a,0,sizeof(a));
for(int k=1;k<=T;k++)
{
scanf("%s",s);
int len = strlen(s);
for(int i = 0;i<len;i++)
{
a[s[i]-97]++;
}
int re = 0;
for(int i=0 ;i<= 25;i++)
{
if(a[i] == 0) re++;
}
printf("Case #%d: %d\n",k,26-re);
memset(a,0,sizeof(a));
memset(s,0,sizeof(s));
}
return 0;
}