ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2022-1-9

2022-01-09 21:04:20  阅读:143  来源: 互联网

标签:encoding int double sum 2022 line size


Problem Description

In computer science, a character is a letter, a digit, a punctuation mark or some other similar symbol. Since computers can only process numbers, number codes are used to represent characters, which is known as character encoding. A character encoding system establishes a bijection between the elements of an alphabet of a certain size n and integers from 0 to n−1 . Some well known character encoding systems include American Standard Code for Information Interchange (ASCII), which has an alphabet size 128, and the extended ASCII, which has an alphabet size 256.

For example, in ASCII encoding system, the word wdy is encoded as [119, 100, 121], while jsw is encoded as [106, 115, 119]. It can be noticed that both 119+100+121=340 and 106+115+119=340 , thus the sum of the encoded numbers of the two words are equal. In fact, there are in all 903 such words of length 3 in an encoding system of alphabet size 128 (in this example, ASCII). The problem is as follows: given an encoding system of alphabet size n where each character is encoded as a number between 0 and n−1 inclusive, how many different words of length m are there, such that the sum of the encoded numbers of all characters is equal to k ?

Since the answer may be large, you only need to output it modulo 998244353.

 

 
Input

The first line of input is a single integer T (1≤T≤400) , the number of test cases.

Each test case includes a line of three integers n,m,k (1≤n,m≤105,0≤k≤105) , denoting the size of the alphabet of the encoding system, the length of the word, and the required sum of the encoded numbers of all characters, respectively.

It is guaranteed that the sum of n , the sum of m and the sum of k don't exceed 5×106 , respectively.

 

 
Output

For each test case, display the answer modulo 998244353 in a single line.

 

 

Sample Input

 
4 2 3 3 2 3 4 3 3 3 128 3 340

 
Sample Output

1 0 7 903
**题意:**

 给定n,m,k,要求个m个格子填数,使每个数在[0,n-1]范围内,且他们的和为k;


给你n m k,

    本质上就是让你求下面这个不定方程的解的组数:

   X1 + X2 + X3+...+ Xm = K, (0<=Xi<n)

 

UVALive 3270 Simplified GSM Network 二分+Floyd

已知B(1≤B≤50)个信号站和C(1≤C≤50)座城市的坐标,坐标的绝对值不大于1000,每个城市使用最近的信号站。

给定R(1≤R≤250)条连接城市线路的描述和Q(1≤Q≤10)个查询,每个基站覆盖一片区域,求相应两城市间通信时最少需要转换信号站的次数。

 

 

#include <bits/stdc++.h>
using namespace std;
const int Max =150;
const int MaxS=150*150;
struct node{
    double x,y;
}BTS[Max], city[Max];

int B, C, R, Q;
int S[Max][Max];

double dis(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int area(double x, double y){ //判断城市(x,y)属于那个基站覆盖
    int i,k;
    double minn,tmp;
    minn = dis(x,y,BTS[1].x,BTS[1].y);
    k=1;
    for(int i=2;i<=B;i++){
        tmp = dis(x,y,BTS[i].x,BTS[i].y);
        if(tmp<minn){
            minn = tmp;
            k = i;
        }
    }
    return k;
}
int get_switch(double x1, double y1, double x2, double y2){
    if(area(x1,y1)==area(x2,y2)) return 0; //俩点(城市)属于同个区域; 不需要转换基站
    if(dis(x1,y1,x2,y2)<1e-6) return 1;  //俩点不属于同个区域 但距离小于1e-6 ; 说明在分界线上,属于俩不同基站区域 需要转换信号
    return get_switch(x1,y1,(x1+x2)/2,(y1+y2)/2)+get_switch((x1+x2)/2,(y1+y2)/2, x2,y2); // 一直二分
}

int main(){
    int ks = 0;
    while(cin>>B>>C>>R>>Q){
        if(B==0&&C==0&&R==0&&Q==0) break;
        for(int i=1; i<=B; i++) cin>>BTS[i].x>>BTS[i].y;
        for(int i=1; i<=C; i++) cin>>city[i].x>>city[i].y;
        memset(S, 0, sizeof(S));
        for(int i=0; i<R; i++){
            int x, y;
            cin>>x>>y;
            S[x][y]=S[y][x]=1;
        }
      //预处理 任意俩城市间的需要转换信号次数
        for(int i=1; i<=C; i++){
            for(int j=i+1; j<=C; j++){
                if(S[i][j]==0)
                   S[i][j]=MaxS;
                else
                    S[i][j] = get_switch(city[i].x,city[i].y,city[j].x,city[j].y);
                S[j][i]=S[i][j];
            }
        }
        for(int i=1;i<=C;i++) S[i][i]=0;

        for(int k=1; k<=C; k++)
            for(int i=1; i<=C; i++)
                for(int j=1; j<=C; j++)
                    if(S[i][j]>S[i][k]+S[k][j])
                        S[i][j] = S[i][k]+S[k][j];
        printf("Case %d:\n", ++ks);
        for(int i=0; i<Q; i++){
            int x, y;
            cin>>x>>y;
            if(S[x][y]>=MaxS)
                puts("Impossible");
            else
               cout<<S[x][y]<<endl;;
        }
    }
}



 

平面切分

思路:画几张图观察一下可以发现一下特点:
1、重边不会影响区域数目。
2、每新加入一条边只要不是重边区域数目必定+1。
3、加入的新边如果与之前加入的边每有一个交点则区域数目+1。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
set<pair<double, double> > line;//存放直线信息
int n,ans=1;
double x, y;
void com(double a, double b) {
	double c, d;
	pair<double, double> in;
	set<pair<double, double> > point;
	for (set<pair<double, double> > ::iterator it = line.begin();it!=line.end();it++) {
		c=it->first, d=it->second;
		if (c!=a) {
			in.first=(d-b)/(a-c); //交点横坐标
			in.second=a*in.first+b;//纵坐标
			point.insert(in);//存放新的直线与其余直线的交点
		}

	}
	ans =point.size();//每有一个点区域数量+1
	point.clear();
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin>>x>>y;
		int len=line.size();
		line.insert(make_pair(x, y));
		if (line.size()!=len) {//重边不会影响平面数目
			ans++;//无论什么情况只要不是重边,加入新的直线后区域数量无条件+1
			com(x,y);
		}
	}
	cout<<ans<<endl;
	return 0;
}

 

标签:encoding,int,double,sum,2022,line,size
来源: https://www.cnblogs.com/yhj-coisini/p/15782142.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有