p1 背包 tyvj1329
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
type list=record
num,len:longint;
name:string;
end;
var n,i,j,k,long,ans:longint;
a:array[1..20000]of list;
f:Array[0..2000000]of longint;
c:char;
begin
readln(n);
readln(c);
readln(long);
for i:=1 to n do
begin
readln(a[i].num,a[i].name);
delete(a[i].name,1,1);
a[i].len:=length(a[i].name);
end;
if c='N' then
begin
fillchar(f,sizeof(f),127);
f[0]:=0;
for i:=1 to n do
for j:=long downto 1 do
if f[j]>f[j-1]+a[i].num then f[j]:=f[j-1]+a[i].num;
if f[long]>2000000 then writeln('DIY') else writeln(f[long]);
end;
if c='L' then
begin
fillchar(f,sizeof(f),127);
f[0]:=0;
for i:=1 to n do
for j:=long downto a[i].len do
if f[j]>f[j-a[i].len]+a[i].num then f[j]:=f[j-a[i].len]+a[i].num;
if f[long]>2000000 then writeln('DIY') else writeln(f[long]);
end;
end.
p2 数学 tyvj1330
#include<fstream> #include<cmath> //#include<iostream> using namespace std; ifstream cin("tyvj.txt"); ofstream cout("tyvj.out"); int n; long long x,y=1; int main() { cin>>n; int num=n; int t=(int)sqrt((double)n); for (int i=2;i<=t;i++) { long long num=0; while ((n%i)==0) { n/=i; num++; } if (num%2==1) y*=i; } y*=n; x=num+y; long long d=num*y; long long dd=2*(long long)sqrt((double)d); x+=dd; cout<<x<<endl; return 0; }
//#include<fstream> #include<iostream> #include<cmath> #include<cstring> #define maxe 100010 using namespace std; //ifstream cin("tyvj.txt"); //ofstream cout("tyvj.out"); int n,o=0; struct node { int x,n; }e[maxe]; int k[maxe],f[maxe],ans,b[maxe]; bool v[maxe]; int abs(int x) { if (x<0) x=-x; return x; } void add(int x,int y) { e[++o].x=y; e[o].n=k[x]; k[x]=o; } void init() { cin>>n; int x,y; for (int i=1;i<n;i++) { cin>>x>>y; add(x,y); add(y,x); } } void dfs(int x,int y) { int t=k[y]; v[y]=1; while (t) { if (!v[e[t].x]) {dfs(t,e[t].x);f[x]+=f[t];} t=e[t].n; } f[x]++; } int main() { init(); dfs(0,1); int m=n/2; ans=99999999; for (int i=1;i<=2*n;i++) { if (abs(m-f[i])<ans) { memset(b,0,sizeof(b)); ans=abs(m-f[i]); b[0]=1; b[1]=i; }else if ((abs(m-f[i]))==ans) { b[++b[0]]=i; } } for (int i=1;i<=b[0];i++) cout<<(b[i]+1)/2<<endl; return 0; }