题目大意:略
思路:处理字符串,将字符串中所需要的数据都提取出来然后计算即可
#include
#define int long long
using namespace std;
string s[]= {"ATK Rate+","ATK+","Crit DMG Rate+","Crit Rate+"};//作为匹配字符串
double atk[6],Crate[6],Cdrate[6],atkr[6],sum;//分别记录需要的对应数据
double ATK=1500,cr=0.05,cdr=0.5;
double fe(double x,double y,double c,double cd) {//统计最后获得的E
double a=ATK*(1+x)+y;
return a*max(1-cr-c,0.0)+a*(1+cd+cdr)*min(cr+c,1.0);
}
signed main() {
for(int i=1; i<=5; i++) {
string str;
for(int k=0; k<5; k++) {
getline(cin,str);
for(int j=0; j<4; j++) {
int pos=str.find(s[j],0),len=s[j].length();
//判断是否能找到对应的字符串
if(pos==string ::npos)continue;//找不到就跳过
if(j==1) {
double x=stod(str.substr(len));
atk[i]=x;//记录对应的值,也可以累和
} else {
double x=stod(str.substr(len));
switch(j) {
case 0:
atkr[i]=x*0.01;//注意是比率
break;
case 2:
Cdrate[i]=x*0.01;
break;
case 3:
Crate[i]=x*0.01;
break;
}
}
}
}
}
double x=0,y=0,c=0,cd=0;
for(int i=1; i<=5; i++) {
x+=atkr[i];
y+=atk[i];
c+=Crate[i];
cd+=Cdrate[i];
}
printf("%.10f",fe(x,y,c,cd));
return 0;
}
题目大意:给出三个整数n , d , c,需要构造出有n个点的图能够被分成c个连通块,每个连通块内的每个点必须连接d个其它点。
思路:分情况考虑,每个图内的每一个点的度数必须是d,那么每个图至少需要d+1个点那么如果(d+1)*c
#include
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e5+5;
set<int> s[N];
queue<int> q;
void graph(int n,int start,int en)
{
int cnt=0;
int ma=en-start;
for(int i = start;i <= en;i ++)
{
if(i!=n)
{
cout << i;
cnt++;
if(cnt < ma)
{
cout << " ";
}
}
}
cout << endl;
}
void connect(int a,int b)
{
s[a].insert(b);
s[b].insert(a);
}
bool graph2(int start,int en,int d)
{
connect(en,start);
connect(en,en-1);
connect(start,start+1);
connect(start,en);
for(int i = start+1;i <= en-1;i++)
{
connect(i,i+1);
connect(i,i-1);
}
for(int i = start;i <= en;i++)
{
if(s[i].size()<d)
{
q.push(i);
}
}
while(!q.empty())
{
int a,b;
a=q.front();
q.pop();
if(q.empty())
{
return false;
}
while(s[a].size()<d)
{
b=q.front();
q.pop();
if(s[a].count(b)==0)
{
connect(a,b);
}
if(s[b].size()<d)
{
q.push(b);
}
}
}
return true;
}
void solve()
{
int n,d,c;
scanf("%d%d%d",&n,&d,&c);
if(d==0)
{
if(c!=n)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
}
else if(d==1)
{
if(n&1||c!=n/2)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
for(int i = 1;i <= n;i++)
{
if(i&1)
{
cout << i+1 << endl;
}
else
{
cout << i-1 << endl;
}
}
}
}
else if((d+1)*c>n)
{
cout << "No" << endl;
}
else
{
if(!graph2((c-1)*(d+1)+1,n,d))
{
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
for(int j = 1;j <= c-1;j++)
{
for(int i = j*(d+1)-d;i <= j*(d+1);i++)
{
graph(i,j*(d+1)-d,j*(d+1));
}
}
set<int>::iterator it;
for(int i = (c-1)*(d+1)+1;i <= n;i++)
{
it = s[i].begin();
for(;it!=s[i].end();it++)
{
cout << *it << " ";
}
cout << endl;
}
}
}
}
int main()
{
// freopen("in.txt","r",stdin);
int t = 1;
// scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}
题目大意:队友推出了个规律,然后我用Java的大数敲出来的,这里只放代码了,详细题解不写了
package work;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n=input.nextInt();
BigDecimal resBigDecimal = factorial(n);
resBigDecimal=resBigDecimal.multiply(resBigDecimal);
resBigDecimal=resBigDecimal.divide(pow(n, n),12,RoundingMode.HALF_UP);
System.out.println(resBigDecimal.toString());
input.close();
}
static BigDecimal pow(int n,int p)
{
BigDecimal N=BigDecimal.valueOf(n);
BigDecimal resBigDecimal=BigDecimal.valueOf(1);
for(int i = 1;i <= p;i++)
{
resBigDecimal=resBigDecimal.multiply(N);
}
return resBigDecimal;
}
static BigDecimal factorial(int n)
{
BigDecimal res = new BigDecimal("1");
for(int i = 1;i <= n;i++)
{
res=res.multiply(BigDecimal.valueOf(i));
}
return res;
}
}