2014 Multi-University Training Contest 9

F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Boring Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 124    Accepted Submission(s): 67


Problem Description
Number theory is interesting, while this problem is boring.

Here is the problem. Given an integer sequence a 1, a 2, …, a n, let S(i) = {j|1<=j<i, and a j  is a multiple of a i}. If S(i) is not empty, let f(i) be the maximum integer in S(i); otherwise, f(i) = i. Now we define bi as a f(i). Similarly, let T(i) = {j|i<j<=n, and a j  is a multiple of a i}. If T(i) is not empty, let g(i) be the minimum integer in T(i); otherwise, g(i) = i. Now we define c i  as a g(i). The boring sum of this sequence is defined as b 1  * c 1  + b 2  * c 2  + … + b n  * c n.

Given an integer sequence, your task is to calculate its boring sum.
 

Input
The input contains multiple test cases.

Each case consists of two lines. The first line contains an integer n (1<=n<=100000). The second line contains n integers a 1, a 2, …, a n  (1<= a i<=100000).

The input is terminated by n = 0.
 

Output
Output the answer in a line.
 

Sample Input
      
      
5 1 4 2 3 9 0
 

Sample Output
      
      
136
Hint
In the sample, b1=1, c1=4, b2=4, c2=4, b3=4, c3=2, b4=3, c4=9, b5=9, c5=9, so b1 * c1 + b2 * c2 + … + b5 * c5 = 136.

思路:对于输入的数列,从前往后扫描一遍,对于每个数,都更新一下它的约数的左边最近倍数的值(b值);

同样地,从后往前扫描一遍,对于每个数,都更新一下它的约数的右边最近倍数的值(c值)。最后直接求所有b*c的和即可。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>

#define N 100005
#define M 15
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b)

using namespace std;

int n;
ll a[N],b[N],c[N];
int vis[N];
ll ans;

int main()
{
    int i;
   // freopen("data.in","r",stdin);
    //scanf("%d",&T);
    //for(int cnt=1;cnt<=T;cnt++)
    //while(T--)
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0) break;
        ans=0;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        memset(vis,0,sizeof(vis));
        for(i=1;i<=n;i++){
            scanf("%I64d",&a[i]);
        }

        vis[ a[1] ]=1;
        for(i=2;i<=n;i++){
            for(ll j=1;j*j<=a[i];j++){
                if(a[i]%j!=0) continue;
                if(vis[j]!=0){
                    b[ vis[j] ]=a[i];
                    vis[j]=0;
                }
                ll te=a[i]/j;
                if(vis[te]!=0){
                    b[ vis[te] ]=a[i];
                    vis[te]=0;
                }
            }
            vis[ a[i] ]=i;
        }


        for(i=1;i<=n;i++){
            if(b[i]==0) b[i]=a[i];
        }

        memset(vis,0,sizeof(vis));
        vis[ a[n] ]=n;
        for(i=n-1;i>=1;i--){
            for(ll j=1;j*j<=a[i];j++){
                if(a[i]%j!=0) continue;
                if(vis[j]!=0){
                    c[ vis[j] ]=a[i];
                    vis[j]=0;
                }
                ll te=a[i]/j;
                if(vis[te]!=0){
                    c[ vis[te] ]=a[i];
                    vis[te]=0;
                }
            }
            vis[ a[i] ]=i;
        }

        for(i=1;i<=n;i++){
            if(c[i]==0) c[i]=a[i];
        }

        for(i=1;i<=n;i++){
            ans+=b[i]*c[i];
        }
        printf("%I64d\n",ans);

    }

    return 0;
}

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 100010
#define MAXM 2000010
#define MAXNODE MAXN*8
#define MOD 999983
typedef long long LL;
using namespace std;
LL N,a[MAXN];
vector<LL> vis[MAXN];
int main(){
    while(scanf("%I64d",&N)!=EOF&&N){
        memset(vis,0,sizeof(vis));
        LL M=-1;
        for(LL i=1;i<MAXN;i++) vis[i].clear();
        for(LL i=1;i<=N;i++){
            scanf("%I64d",&a[i]);
            vis[a[i]].push_back(i);
            M=max(M,a[i]);
        }
        for(LL i=1;i<=M;i++) sort(vis[i].begin(),vis[i].end());
        LL ans=0;
        for(LL i=1;i<=N;i++){
            LL MAX=-1,MIN=INF;
            for(LL j=a[i];j<=M;j+=a[i]) if(vis[j].size()>0){
                LL p=lower_bound(vis[j].begin(),vis[j].end(),i)-vis[j].begin(),L=vis[j].size();
                if(L==1){
                    if(vis[j][0]<i) MAX=max(MAX,vis[j][0]);
                    if(vis[j][0]>i) MIN=min(MIN,vis[j][0]);
                    continue;
                }
                if(p==L){
                    MAX=max(MAX,vis[j][p-1]);
                    continue;
                }
                LL p2=p-1;
                if(vis[j][p]==i) p++;
                if(p<L) MIN=min(MIN,vis[j][p]);
                if(p2>=0) MAX=max(MAX,vis[j][p2]);
            }
            if(MAX==-1) MAX=i;
            if(MIN==INF) MIN=i;
            ans+=a[MAX]*a[MIN];
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Fast Matrix Calculation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 147    Accepted Submission(s): 82


Problem Description
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learning something about matrix, so he decided to make a crazy problem for her.

Bob has a six-faced dice which has numbers 0, 1, 2, 3, 4 and 5 on each face. At first, he will choose a number N (4 <= N <= 1000), and for N times, he keeps throwing his dice for K times (2 <=K <= 6) and writes down its number on the top face to make an N*K matrix A, in which each element is not less than 0 and not greater than 5. Then he does similar thing again with a bit difference: he keeps throwing his dice for N times and each time repeat it for K times to write down a K*N matrix B, in which each element is not less than 0 and not greater than 5. With the two matrix A and B formed, Alice’s task is to perform the following 4-step calculation.

Step 1: Calculate a new N*N matrix C = A*B.
Step 2: Calculate M = C^(N*N).  
Step 3: For each element x in M, calculate x % 6. All the remainders form a new matrix M’.
Step 4: Calculate the sum of all the elements in M’.  

Bob just made this problem for kidding but he sees Alice taking it serious, so he also wonders what the answer is. And then Bob turn to you for help because he is not good at math.
 

Input
The input contains several test cases. Each test case starts with two integer N and K, indicating the numbers N and K described above. Then N lines follow, and each line has K integers between 0 and 5, representing matrix A. Then K lines follow, and each line has N integers between 0 and 5, representing matrix B.

The end of input is indicated by N = K = 0.
 

Output
For each case, output the sum of all the elements in M’ in a line.
 

Sample Input
       
       
4 2 5 5 4 4 5 4 0 0 4 2 5 5 1 3 1 5 6 3 1 2 3 0 3 0 2 3 4 4 3 2 2 5 5 0 5 0 3 4 5 1 1 0 5 3 2 3 3 2 3 1 5 4 5 2 0 0
 

Sample Output
       
       
14 56

矩阵快速幂,比赛的时候真是脑残了。。。
ABABABAB...=A(BA)(BA)(BA)....B这样就成了6*6的矩阵
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn=10;
const int MOD=6;
int N,K;
int a[1010][1010],b[1010][1010],ans[1010][1010];
struct Matrix
{
    int mat[maxn][maxn];
    Matrix(){memset(mat,0,sizeof(mat));}
    void clear(){memset(mat,0,sizeof(mat));}
}A,B,C;
Matrix pow_mul(Matrix &A,Matrix &B)
{
    Matrix res;
    for(int k=1;k<=K;k++)
        for(int i=1;i<=K;i++)
        {
            if(A.mat[i][k]==0)continue;
            for(int j=1;j<=K;j++)
            {
                if(B.mat[k][j]==0)continue;
                res.mat[i][j]=(res.mat[i][j]+A.mat[i][k]*B.mat[k][j])%MOD;
            }

        }

    return res;
}
Matrix pow(Matrix A,int x)
{
    Matrix res;
    for(int i=0;i<=K;i++)res.mat[i][i]=1;
    while(x)
    {
        if(x&1)res=pow_mul(res,A);
        A=pow_mul(A,A);
        x>>=1;
    }
    return res;
}
int main()
{
    while(scanf("%d%d",&N,&K)!=EOF&&(N||K))
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(ans,0,sizeof(ans));
        C.clear();
        for(int i=1;i<=N;i++)
            for(int j=1;j<=K;j++)
            scanf("%d",&a[i][j]);
        for(int i=1;i<=K;i++)
            for(int j=1;j<=N;j++)
            scanf("%d",&b[i][j]);

        for(int i=1;i<=K;i++)
            for(int j=1;j<=K;j++)
            for(int k=1;k<=N;k++)
            C.mat[i][j]=(C.mat[i][j]+b[i][k]*a[k][j]%MOD)%MOD;
        C=pow(C,N*N-1);
        for(int i=1;i<=N;i++)
            for(int j=1;j<=K;j++)
            for(int k=1;k<=K;k++)
            ans[i][j]=(ans[i][j]+a[i][k]*C.mat[k][j]%MOD)%MOD;
        memset(a,0,sizeof(a));
        for(int i=1;i<=N;i++)
            for(int j=1;j<=N;j++)
            for(int k=1;k<=K;k++)
            a[i][j]=(a[i][j]+ans[i][k]*b[k][j]%MOD)%MOD;
        int cnt=0;
        for(int i=1;i<=N;i++)
            for(int j=1;j<=N;j++)
                cnt+=a[i][j];
        printf("%d\n",cnt);
    }
    return 0;
}

F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Killing Monsters

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 233    Accepted Submission(s): 134


Problem Description
Kingdom Rush is a popular TD game, in which you should build some towers to protect your kingdom from monsters. And now another wave of monsters is coming and you need again to know whether you can get through it.

The path of monsters is a straight line, and there are N blocks on it (numbered from 1 to N continuously). Before enemies come, you have M towers built. Each tower has an attack range [L, R], meaning that it can attack all enemies in every block i, where L<=i<=R. Once a monster steps into block i, every tower whose attack range include block i will attack the monster once and only once. For example, a tower with attack range [1, 3] will attack a monster three times if the monster is alive, one in block 1, another in block 2 and the last in block 3.

A witch helps your enemies and makes every monster has its own place of appearance (the ith monster appears at block Xi). All monsters go straightly to block N.

Now that you know each monster has HP Hi and each tower has a value of attack Di, one attack will cause Di damage (decrease HP by Di). If the HP of a monster is decreased to 0 or below 0, it will die and disappear.
Your task is to calculate the number of monsters surviving from your towers so as to make a plan B.
 

Input
The input contains multiple test cases.

The first line of each case is an integer N (0 < N <= 100000), the number of blocks in the path. The second line is an integer M (0 < M <= 100000), the number of towers you have. The next M lines each contain three numbers, Li, Ri, Di (1 <= Li <= Ri <= N, 0 < Di <= 1000), indicating the attack range [L, R] and the value of attack D of the ith tower. The next line is an integer K (0 < K <= 100000), the number of coming monsters. The following K lines each contain two integers Hi and Xi (0 < Hi <= 10^18, 1 <= Xi <= N) indicating the ith monster’s live point and the number of the block where the ith monster appears.

The input is terminated by N = 0.
 

Output
Output one line containing the number of surviving monsters.
 

Sample Input
       
       
5 2 1 3 1 5 5 2 5 1 3 3 1 5 2 7 3 9 1 0
 

Sample Output
       
       
3

求出每个点的伤害,然后求和,树状数组优化
#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 100010
#define MAXM 2000010
#define MAXNODE MAXN*8
#define MOD 999983
typedef long long LL;
using namespace std;
LL N,M,K;
LL c[MAXN],s[MAXN];
LL lowbit(LL x){
    return x&(-x);
}
void add(LL i,LL v){
    while(i<=N){
        c[i]+=v;
        i+=lowbit(i);
    }
}
LL sum(LL i){
    LL ret=0;
    while(i>0){
        ret+=c[i];
        i-=lowbit(i);
    }
    return ret;
}
int main(){
    while(scanf("%I64d",&N)!=EOF&&N){
        scanf("%I64d",&M);
        memset(c,0,sizeof(c));
        for(LL i=0;i<M;i++){
            LL l,r,v;
            scanf("%I64d%I64d%I64d",&l,&r,&v);
            add(N-r+1,v);
            add(N-l+2,-v);
        }
        memset(s,0,sizeof(s));
        s[N]=sum(1);
        for(int i=N-1;i>=1;i--) s[i]=s[i+1]+sum(N-i+1);
        scanf("%I64d",&K);
        LL ans=0;
        for(LL i=0;i<K;i++){
            LL h,x;
            scanf("%I64d%I64d",&h,&x);
            if(s[x]<h) ans++;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Improving the GPA

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 123    Accepted Submission(s): 92


Problem Description
Xueba: Using the 4-Point Scale, my GPA is 4.0.

In fact, the AVERAGE SCORE of Xueba is calculated by the following formula:
AVERAGE SCORE = ∑(Wi * SCOREi) / ∑(Wi) 1<=i<=N

where SCOREi represents the scores of the ith course and Wi represents the credit of the corresponding course.

To simplify the problem, we assume that the credit of each course is 1. In this way, the AVERAGE SCORE is ∑(SCOREi) / N. In addition, SCOREi are all integers between 60 and 100, and we guarantee that ∑(SCOREi) can be divided by N.

In SYSU, the university usually uses the AVERAGE SCORE as the standard to represent the students’ level. However, when the students want to study further in foreign countries, other universities will use the 4-Point Scale to represent the students’ level. There are 2 ways of transforming each score to 4-Point Scale. Here is one of them.  


The student’s average GPA in the 4-Point Scale is calculated as follows:
GPA = ∑(GPAi) / N

So given one student’s AVERAGE SCORE and the number of the courses, there are many different possible values in the 4-Point Scale. Please calculate the minimum and maximum value of the GPA in the 4-Point Scale.  
 

Input
The input begins with a line containing an integer T (1 < T < 500), which denotes the number of test cases. The next T lines each contain two integers AVGSCORE, N (60 <= AVGSCORE <= 100, 1 <= N <= 10).
 

Output
For each test case, you should display the minimum and maximum value of the GPA in the 4-Point Scale in one line, accurate up to 4 decimal places. There is a space between two values.
 

Sample Input
       
       
4 75 1 75 2 75 3 75 10
 

Sample Output
       
       
3.0000 3.0000 2.7500 3.0000 2.6667 3.1667 2.4000 3.2000

思路:枚举每个分数段有多少门课程
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <cctype>
#include <algorithm>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int mod = 99999997;
const int MAX = 0x3f3f3f3f;
const int maxn = 100005;
const int N = 100005;
int t, n, av, tot;
bool check1(int i1, int i2, int i3, int i4, int i5) {
    if(i5 < 0) return false;
    int ans = i1*85 + i2*80 + i3*75 + i4*70 + i5*60;
    if(ans <= tot) return true;
    return false;
}
bool check2(int i1, int i2, int i3, int i4, int i5) {
    if(i5 < 0) return false;
    int ans = i1*100 + i2*84 + i3*79 + i4*74 + i5*69;
    if(ans >= tot) return true;
    return false;
}
double F1(double i1, double i2, double i3, double i4, double i5) {
    return i1*4 + i2*3.5 + i3*3 + i4*2.5 + i5*2;
}

int main()
{freopen("in.txt","r",stdin);
    cin >> t;
    while(t--) {
        cin >> av >> n;
        tot = av*n;
        double ans1 = 10000000000000,ans = 0;
        for(int i1 = 0; i1 <= n; i1++)
            for(int i2 = 0; i1 + i2 <= n; i2++)
                for(int i3 = 0; i1 + i2 + i3 <= n; i3++)
                    for(int i4 = 0; i1 + i2 + i3 + i4 <= n; i4++) {
                        int i5 = n - i1 - i2 - i3 - i4;
                        if(check2(i1, i2, i3, i4, i5)&&check1(i1, i2, i3, i4, i5)) {
                            double sum = F1(i1, i2, i3, i4, i5);
                            ans1 = min(ans1, sum);
                            ans = max(ans, sum);
                        }
                    }
        printf("%.4lf %.4lf\n", ans1/n,ans/n);
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值