10034 - Freckles

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010452161/article/details/20367405


点击打开链接


求最小生成树,可用PRIM 也可用 KRUSKRAL 。




#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int father[110];
double x[110],y[110];
typedef struct{
    int st;
    int en;
    double dist;
}Node;
Node g[5100];

int cmp(const void *a,const void *b){
    Node * _a = (Node *) a;
    Node * _b = (Node *) b;
    return _a->dist - _b->dist;
}

int finds(int x){
    return father[x] = x ? x:  finds(father[x]);
}

int main(){
    int i,j;
    int t,n;
    int cnt;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(i = 0;i<n;i++) scanf("%lf%lf",&x[i],&y[i]);
        cnt = 0;
        for(i = 0;i<n;i++){
            for(j = i+1;j<n;j++) {
                g[cnt].st  = i;
                g[cnt].en = j;
                g[cnt++].dist = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            }
        }
        qsort(g,cnt,sizeof(g[0]),cmp);
        for(i = 0;i<n;i++) father[i] = i;
        double ans = 0;
        for(i = 0;i<cnt;i++){
            int fx = finds(g[i].st);
            int fy = finds(g[i].en);

这里只给出 KRUSKRAL 的部分代码。望请谅解。


阅读更多

java.lang.SecurityException: No active admin owned by uid 10034 for policy #3

03-10

最近在做一个一键锁屏的程序,可是总是产生这个异常( java.lang.SecurityException: No active admin owned by uid 10034 for policy #3)。。试过很多方法也无法消除这个异常,Google上资料也很少。。求帮助啊。。。这个是什么意思啊。。。rn(我是在条件成立时启动这个activity以实现锁屏的目的)rn[code=Java]public class tempActivity extends Activity rn private static final String TAG = "tempActivity"; rn private DevicePolicyManager policyManager;rn private ComponentName componentName;rnrn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.temp);rn Log.e(TAG, "Activity created~");rn policyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);rn componentName = new ComponentName(this, AdminReceiver.class);rn mylock();rn rnrn private void mylock() rn boolean active = policyManager.isAdminActive(componentName);rn if (!active) // 若无权限rn Log.e(TAG, "没有权限~");rn activeManage(); // 去获得权限rn policyManager.lockNow(); // 并锁屏rn else rn Log.e(TAG, "已经有权限");rn policyManager.lockNow(); // 直接锁屏rn rn this.finish();rn rnrn private void activeManage() rn Log.e(TAG, "activeManage");rn Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);rn intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);rn intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "developers:liushuaikobe");rn startActivityForResult(intent, 1);rn rn[/code]

没有更多推荐了,返回首页